given this html:
<li id="the_list_item"><img src="some_img"></li>
and this selectior:
$("#the_list_item")
I want to get the full html from the object return by the jQuery selector.
Using:
$("#the_list_item").html()
...just gives me the inner html (the <img src="some_img">
part)
But since:
$("#the_list_item").attr("id")
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?
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.
Here my solution, No jQuery required!
Alternatively, it could be get the reference of element by means of jQuery, and then get the outerHTML.
One way is to create your own wrapper:
...do your thing, then unwrap:
I'm not sure if this works, but it might be worth a shot:
Have you tried
$("#the_list_item").parent().html()
?Unfortunately, the outerHTML solution (accepted solution above) did not work for me on FireFox 9 / Windows 7 / JQuery 1.7 ...
Here is something that worked for me, according to Chetan Sastry (answer above):
Here you can find a nice solution in the form of the code for a jQuery outerHtml plugin: http://yelotofu.com/2008/08/jquery-outerhtml/