Home > front end >  JQueryDOM node operation
JQueryDOM node operation

Time:12-15

To create the DOM node JavaScript
Create a process:
1. Create the document element. The createElement method ()
2. For the node to add attribute element. The setAttribute ();
3. You can use the innerText or innerHTML attribute to add text or HTML content
4. Use the parentElement. The appendChild () method will create the new node is added to the parent node
JQuery node created: $() function processing, $(" HTML structure ")
JQuery created node is a jQuery object
Node insert:
Append (content | fn) : additional content to the inside of every matched element:
$(A), append (B); Will be added to A
BAppendTo (content) : all of the matched elements added to another in a specified element in the collection of elements:
$(A). AppendTo (B);
in the appended to the BConclusion: function of these two methods are the same, the main difference is that grammar - & gt; The location of the content and target different
The prepend (content) : prepend content to the inside of every matched element:
$(A). The prepend (B); Will be added to A B (and append to add elements of the position difference)
PrependTo (content) : all of the matched elements lead to another, specified element in the collection of elements:
$(A). PrependTo (B);
in the appended to the BNodes of the external insert:
After (content | fn) : insert content after each of the matched elements:
$(A). After (B); On A behind B
elementBefore (the content | fn) : insert content before each of the matched elements:
$(A). Before (B); On A front insert B
elementInsertAfter (content) : insert all of the matched elements to another, the back of the specified element set:
$(A). InsertAfter (B) at the back of the B insert A element, with $(A) after (B) is the opposite of the operation, but the function as
InsertBefore (content) : insert all of the matched elements to another, specified in the front of the set of elements:
$(A). The insertBefore (B) insert A element, in front of B and $(A). Before (B) is the opposite of the operation, but the function as
Node deletion:
1. The empty () removes all child nodes from the set of matched elements
2. Remove ([expr]) to delete all of the matched elements from the DOM, jQuery expression of expr: used to filter element
3. Detach () to delete all of the matched elements from the DOM, this method does not put the matching element is removed from the jQuery object,
Thus it can be in the future to use these matching element, and remove (), all bound events,
Additional data will be retained; $(" div "). The detach () this will remove the object, but not only shows the effect of the just,
And there is a memory, when you append, will flow back to the document, so it is displayed again,

CodePudding user response:

  • Related