在JQuery中获取外部div

时间:2011-08-05 09:40:40

标签: jquery jquery-selectors

  

可能重复:
  Get selected element's outer HTML

我正在上这样的课程:

   <div class="className">
      content in here
   </div>

然后我在JQuery中得到它:

$('.className').html()

仅输出:

content in here

当我希望它能得到所有东西时,包括父div。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

$('.className').clone().wrap('<div></div>').parent().html();

http://jsfiddle.net/ipr101/WX69N/