javascript - Get whole tags including selected tag in jquery -


this question has answer here:

my html content

<div class="div1>       div1 </div>  <div class="div2>       div2 </div> 

my jquery code is

$("div").click(function(){        alert($(this).html()); }); 

this return either "div1" or "div2" based on click. whole tags <div class="div1"> div1 </div> "this" object. there anyway that...?

you need outer html of element. can achieve creating temporary clone of element itself. example:

$('div').on('click', function() {     alert( $('<div>').append( $(this).clone() ).html() ); }); 

alternatively, can use built-in outerhtml property, example:

$('div').on('click', function() {     alert( this.outerhtml ); }); 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -