5

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?

4

1 に答える 1

10

あなたはouterHTMLを使用することができます

ライブデモ

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

または、jQuery を使用してクロス ブラウザーの利点を得ることができます。

ライブデモ

alert($('<div></div>').append($('#149656222').clone()).html());
于 2013-02-11T09:20:16.897 に答える