Latest web development tutorials

jQuery contents () method

jQuery traversal methods jQuery traversal methods

Examples

Find <div> element within all text nodes, and put them with the <b> element wrapped up:

$("div").contents().filter("em").wrap("<b/>");

try it"

Definition and Usage

contents () method returns all direct child elements, including elements of the selected text and comment nodes.

Text node is the actual text displayed by the element.

This method children () similar method, except that it returns the text and comment nodes. If in the same domain, contents () method can also visit the iframe HTML.


grammar

$(selector).contents()


jQuery traversal methods jQuery traversal methods