1

lets say I have a

<div id="god">
Supertext
</div>

I want to assign

<div id="god">
Supertext
</div>

to a variable

.text()
.html()

only gets "supertext" as a value.

$("#god")
$("#god").clone

returns an object

I don't want to wrap the object and get it's html, because it's time consuming. How can I select the whole item and assign it to a variable in javascript?

Uğur Gümüşhan
  • 2,387
  • 4
  • 33
  • 59
  • Does this help? http://stackoverflow.com/questions/2419749/get-selected-elements-outer-html – zigg Mar 31 '12 at 23:25

2 Answers2

2

For the browsers that support it you can use the outerHTML

$("#god")[0].outerHTML;
Gabriele Petrioli
  • 183,160
  • 33
  • 252
  • 304
0

Don't use jQuery selectors, just to use native javascript functions!

document.getElementById('#god').outerHTML
gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355