jQuery选择器返回的对象的完整HTML [英] full HTML of object returned by jQuery selector
问题描述
给出了此html:
<li id="the_list_item"><img src="some_img"></li>
和这个选择器:
$("#the_list_item")
我想从jQuery选择器返回的对象中获取完整的html.
I want to get the full html from the object return by the jQuery selector.
使用:
$("#the_list_item").html()
...只是给了我内部的html(<img src="some_img">
部分)
...just gives me the inner html (the <img src="some_img">
part)
但是由于:
$("#the_list_item").attr("id")
给我'the_list_item',这表明整个列表项确实包含在返回的对象中..那么如何从该对象中获取完整的代码?
gives me 'the_list_item', this indicated that the whole list item is indeed included in the object returned.. so how do I get the full code from that object?
我想从对象中获取一个字符串:<li id="the_list_item"><img src="some_img"></li>
,但是找不到解决方法.
I want to get a String: <li id="the_list_item"><img src="some_img"></li>
from my object, but can't find the way to do it.
推荐答案
一种方法是创建自己的包装器:
One way is to create your own wrapper:
$("#the_list_item").wrap('<div>').parent().html();
...做你的事情,然后拆开:
...do your thing, then unwrap:
$("#the_list_item").unwrap();
这篇关于jQuery选择器返回的对象的完整HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!