Home >Web Front-end >JS Tutorial >Explanation of the difference between empty() and remove() in jquery_jquery
1.empty() only removes all child nodes in the specified element. Take $("p").empty() as an example, it just removes
dsfsd< The text in /p> is removed, leaving
, which still retains its position in the dom.2.remove([expr]) deletes it from the dom without retaining its position.
Example:
Hello
Worldwelcome
Execute $("p").empty() and the result is
WorldExecute $("p").remove() and the result is World