2

if i call

jquery("a").html()

i get what is INSIDE of the "a" tag

if i want the entire html, what do i call?

<a>xxxx</a>
meow
  • 26,636
  • 31
  • 113
  • 173
  • 2
    outerHTML is by the way originated here: http://brandonaaron.net/blog/2007/06/17/jquery-snippets-outerhtml – BalusC Apr 05 '10 at 04:41

3 Answers3

7
jQuery.fn.outerHTML = function() {
    return jQuery('<div />').append(this.eq(0).clone()).html();
}
jQuery('a').outerHTML(); // <a>xxxx</a>
eyelidlessness
  • 60,651
  • 11
  • 88
  • 93
1

What you want is outerHTML and there is no direct way to get that in jQuery. You can write your own function

jQuery.fn.outerHTML = function() {
    return $('<div>').append( this.eq(0).clone() ).html();
};

$("yourselector").outerHTML();

In javascript you can use outerHTML, but isn't compatible with every browser. Take a loot at outerHTML

rahul
  • 179,909
  • 49
  • 229
  • 260
0

Check out the jQuery .outerHTML() plug-in from http://darlesson.com/jquery/outerhtml/. To get your HTML from the matched element you need something like:

$("a").outerHTML();
Darlesson
  • 4,814
  • 2
  • 19
  • 25