Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all html including wrapper div

Tags:

jquery

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

The 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 displays only this much:

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

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

like image 980
None Avatar asked Feb 11 '13 09:02

None


1 Answers

You can use outerHTML

Live Demo

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

Or you can use jQuery to get the cross browser benifits

Live Demo

alert($('<div></div>').append($('#149656222').clone()).html());
like image 111
Adil Avatar answered Nov 20 '22 03:11

Adil