Select all html including shell div

I am trying to select a div and its contents using jquery.

div looks like this:

 <div class="fav-list" id="149656222">
  <ul>
    <li>hai</li>
    <li>hooy</li>
  </ul>
</div>

and my code

  alert($('#149656222').html());

this only displays this:

<ul>
    <li>hai</li>
    <li>hooy</li>
  </ul>

And I need the whole div to be selected, what do I need to do for this?

+5
source share
1 answer

You can use outerHTML

Live demo

alert($('#149656222')[0].outerHTML);

Or you can use jQuery to take advantage of cross browser

Live demo

alert($('<div></div>').append($('#149656222').clone()).html());
+10
source

All Articles