0

Possible Duplicate:
Get selected element's outer HTML

I want to alert the html of class/id with its children AND itselfs element like this:

<div id="selectme">somechildren...</div>

I want the exact same alert as the HTML code above by selecting the "selectme" ID.. whats the function(s) for this?

Community
  • 1
  • 1
ggzone
  • 3,575
  • 8
  • 35
  • 59

3 Answers3

2

If the element in question has siblings, you can clone the selected element, wrap a parent element around it (in this case I've used a div), select that new parent element, and get the html of that:

var html = $("#selectme").clone().wrap("<div>").parent().html();

Here's a working example.

If the element doesn't have any siblings, you can just do:

var html = $("#selectme").parent().html();
James Allardice
  • 160,885
  • 21
  • 326
  • 309
0

Try this:

alert($("#selectme").parent().clone().wrap('<div>').parent().html());
Abdul Munim
  • 18,235
  • 7
  • 50
  • 60
0

Something like this:

alert($('#selectme').parent().html())

although your question is pretty blurry...

Didier Ghys
  • 29,970
  • 9
  • 71
  • 78