tags:

views:

116

answers:

2

For example, if the match is <div class="class1">Hello world</div>, I need to return

<div class="class1">Hello world</div>

not just "Hello world".

Thanks!

+2  A: 

Check out this outerHTML plugin.

Michael Haren
+5  A: 

There's no built-in function for getting the outerHTML, but you can use this:

jQuery.fn.outerHTML = function(s) {
return (s)
  ? this.before(s).remove()
  : jQuery("<p>").append(this.eq(0).clone()).html();
}

Then in your selector:
$('.class1').outerHTML() will give you what you are looking for.

Source of function

Jose Basilio
Thank you sir, you are awesome!!!
jeffu
+1 - Awesome, I've favourited this in case I need it some day.
karim79