javascript - accessing DOM elements by jQuery -
say have following dom element in piece of code:
<div id="test"> <div id="t2"> hi <b>gopi</b> , 20 years old. <p id="div2"> <button onclick="alert('lol')">check</button> </p> </div> </div> suppose wanted traverse through contents of div#t2.
$("#t2").children() gives me <b> , <p> tags.
so how should access values array containing "hi am", "<b>....</b>", "and 20 years old.", "<p>.....</p> ??
use native dom node:
$('#t2')[0].childnodes gives array want.
you'll want trim entries before using them using $.trim since actual text node contains whitespace in html.
Comments
Post a Comment