开发者

Get content of DOM element without the parent by using jQuery

开发者 https://www.devze.com 2023-01-23 13:50 出处:网络
Here are some simple examples what I am trying to do: $(\"<li>Foo开发者_如何学Python</li>\")

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消