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
  • 27,476
  • 33
  • 116
  • 177
  • 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
  • 62,413
  • 11
  • 90
  • 94
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
  • 184,426
  • 49
  • 232
  • 263
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
  • 5,742
  • 2
  • 21
  • 26