jQuery DOM |
The Document Object Model is an API which allows developers to access, read, and modify the content of a web page.
JQuery provides methods to manipulate DOM in efficient way. Insted of writing big code to modify the value of any element's attribute or to Extract/Manipulate HTML code from a paragraph or division., was very easy with Jquery DOM.
Different types of Jquery DOM methods :
- after( content )
- It is Used to Insert content after each of the matched elements.
- Example:- $('div').after('<p class="para">This is a after paragraph</p>' );
- before( content )
- It is Used to Insert content before each of the matched elements.
- Example:-$('div').before('<p class="para">This is a before paragraph</p>' );
- append( content )
- It is used to Append new content to the inside of every matched element.
- Example:- $('div').append('<p class="para">This is inside paragraph</p>' );
- appendTo( selector )
- Append all of the matched elements to another, specified, set of elements.
- Example:-$('div').appendTo('#res');
- clone( )
- This is useful for moving copies of the elements to another location in the DOM.
- Example:-$('div').clone().insertAfter('div');
- empty( )
- Remove all child nodes from the set of matched elements.
- Example:-$('div').empty();
- insertAfter( selector )
- Insert all of the matched elements after specified, set of elements.
- Example:-$('div').clone().insertAfter('div');
- insertBefore( selector )
- Insert all of the matched elements before specified, set of elements.
- Example:-$('div').clone().insertBefore('div');
- prepend( content )
- It is used to prepend new content to the inside of every matched element.
- Example:- $('div.demo-box').prepend('<div class="insertion">This text was inserted </div>');
- prependTo( selector )
- Prepend all of the matched elements to another, specified, set of elements.
- Example:-$('<div class="insertion">This text was inserted </div>') .prependTo('div.demo-box');
- remove( expr )
- It will Remove all the matched elements from the DOM
- Example:-$('div.demo-box').remove();
- replaceAll( selector )
- Replaces the elements matched by the specified selector with the matched elements.
- Example:-$('<div class="div"></div>').replaceAll('p' );
- replaceWith( content )
- Replaces all matched elements with the specified HTML or DOM elements.
- Example:-$('div.demo-box') .replaceWith('<div class="insertion">Replacement Box</div>');
- wrap( elem ) / wrap( html )
- Wrap each matched element with the specified element. / Wrap each matched element with the specified HTML content.
- Example:- $('div.demo-box').wrap('<div class="insertion"></div>');
- wrapAll( elem/html )
- Wrap all the elements in the matched set into a single wrapper element.
- Example:- $('div.demo-box').wrapAll('<div class="insertion"></div>');
- wrapInner( elem/html )
- Wrap the inner child contents of each matched element (including text nodes) with a DOM element.
- Example:- $('div.demo-box').wrapInner('<div class="insertion"></div>');
Example:-
Hello Jquery Learner.., This is Main Block
Hello Jquery Learner.., This is Main Block
<script type="text/javascript"> $("#htm").click(function() { var va = $("#p1").html(); $("#p2").html(va); }); $("#txt").click(function() { var va = $("#p1").text(); $("#p2").text(va); }); </script> |
This is Paragraph One This is Paragraph Two |
Post a Comment