3

I'm using jquery to get a row

<tr class="phoneNumber">
   ABC...
</tr>

and when i do $(".phoneNumber").html(), it returns ABC...
Is there a way to get

<tr class="phoneNumber">
   ABC...
</tr>

Thanks in advance

Reda
  • 1,277
  • 1
  • 13
  • 27
  • possible duplicate of [How to get the innerHtml, including the tag, using jQuery?](http://stackoverflow.com/questions/2319213/how-to-get-the-innerhtml-including-the-tag-using-jquery) – Shyju Jul 28 '12 at 05:16
  • http://stackoverflow.com/questions/2419749/get-selected-elements-outer-html has the answer you're after – Dan F Jul 28 '12 at 05:18

2 Answers2

2
(function($) {
  $.fn.outerHTML = function() {
    return $(this).clone().wrap('<div></div>').parent().html();
  }
})(jQuery);

$('.phoneNumber').outerHTML();
Soufiane Hassou
  • 17,257
  • 2
  • 39
  • 75
0

Use outerHTML:

$('.phoneNumber')[0].outerHTML

Or, if compatibility is important to you, use one of the extensions listed at Get selected element's outer HTML.

Community
  • 1
  • 1
Ry-
  • 218,210
  • 55
  • 464
  • 476