Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Dom object's content include itself?

I want to able to get #post content include itself. jQuery's html() method only return content that does not include itself.Trying to get parent object's html does not work in all situation because that object can have siblings.

What is solution for this ?

<div id="post">
     <div>content</div>
<div>
<div></div>
like image 693
AnyOne Avatar asked Jan 17 '23 19:01

AnyOne


1 Answers

Description

jQuery's html() gives you only the innerHTML right. You can do

$("#post")[0].outerHTML

to get the full html but this is not crosser browser compatible.

Check out this jsFiddle Demonstration

You can use this plugin to get a cross browser compatible function .outerHTML()

More Information

  • jQuery - OuterHTML Plugin
  • jQuery.html()
like image 168
dknaack Avatar answered Jan 25 '23 16:01

dknaack