Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get .html AND the container [duplicate]

Tags:

jquery

Possible Duplicate:
jQuery - Get selected element's outer HTML

so I have a div..

<div id="fred">

it has stuff in it

<div id="fred">
  <tr id="thing1">hello1</tr>
  <tr id="thing2">hello2</tr>
</div>

if I call

$("#fred").html();

I get just the items inside:

  <tr id="thing1">hello1</tr>
  <tr id="thing2">hello2</tr>

I want the whole thing:

<div id="fred">
  <tr id="thing1">hello1</tr>
  <tr id="thing2">hello2</tr>
</div>

I know that I can ref using this[0], but it seems like there should be an easier way..

I tried .andSelf() but apparently that doesn't do what I thought it should doo..

like image 639
KevinDeus Avatar asked Jun 05 '26 06:06

KevinDeus


1 Answers

jQuery doesn't support outerHTML: http://api.jquery.com/html/#comment-84945158

(.andSelf is for element sets, not for depth.)

I think the best solution would be el[0].outerHTML (no extra 'plugin' required and native JS s always good)

like image 69
Rudie Avatar answered Jun 06 '26 22:06

Rudie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!