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,661
  • 8
  • 36
  • 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
  • 164,175
  • 21
  • 332
  • 312
0

Try this:

alert($("#selectme").parent().clone().wrap('<div>').parent().html());
Abdul Munim
  • 18,869
  • 8
  • 52
  • 61
0

Something like this:

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

although your question is pretty blurry...

Didier Ghys
  • 30,396
  • 9
  • 75
  • 81