.contents() | jquery get html text
Description:Getthechildrenofeachelementinthesetofmatchedelements,includingtextandcommentnodes.GivenajQueryobjectthatrepresentsasetofDOMelements,the.contents()methodallowsustosearchthroughtheimmediatechildrenoftheseelementsintheDOMtreeandconstructanewjQueryobjectfromthematchingelements.The.contents()and.children()methodsaresimilar,exceptthattheformerincludestextnodesandcommentnodesaswellasHTMLelementsintheresultingjQueryobject.PleasenotethatmostjQueryoperationsdontsupporttextnodesandcommentno...
Description: Get the children of each element in the set of matched elements, including text and comment nodes.
Given a jQuery object that represents a set of DOM elements, the .contents() method allows us to search through the immediate children of these elements in the DOM tree and construct a new jQuery object from the matching elements. The .contents() and .children() methods are similar, except that the former includes text nodes and comment nodes as well as HTML elements in the resulting jQuery object. Please note that most jQuery operations dont support text nodes and comment nodes. The few that do will have an explicit note on their API documentation page.
The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.
As of jQuery 3.2, .contents() returns contents of <template> elements as well.
Consider a simple <div> with a number of text nodes, ...