Here are some simple examples what I am trying to do:
$("<li>Foo开发者_如何学Python</li>")
=> "Foo"
$("<li><span>Foo</span></li>")
=> <span>Foo</span>
$('<li class="foo"><div>Foo</div><div>Bar</div></li>')
=> <div>Foo</div><div>Bar</div>
I know of the jQuery get()
method, but this just gives me the <li>
elments, too. A .children().get()
does not work (at least in the first case). Is there a simple way to achieve that (with built in jQuery methods)?
$("<li>Foo</li>").html()
$("<li><span>Foo</span></li>").html()
$('<li class="foo"><div>Foo</div><div>Bar</div></li>').html()
To get the children of a node including text nodes, use the contents()
method instead of children()
.
精彩评论