Possible duplicate:jQuery get the html of the whole element
will say that I have:
<span>my span</span>
I would like html as a string of this range
I use:
var mySpan = $('span');
what to do with mySpan var to result in the string "<span>my span</span>"
"<span>my span</span>"
thanks for any help
I think this will help: http://jsfiddle.net/HxU7B/2/ .
UPDATE
mySpan[0].outerHTML will take the previous selected node and get its own outerHTML property. Since older versions of Firefox do not have this property, we can use a bit of hacking to get html - just clone the node into a dummy div and then get that div innerHTML: $('<div/>').append(mySpan.clone()).html()
mySpan[0].outerHTML
outerHTML
div
$('<div/>').append(mySpan.clone()).html()
jQuery cannot do this, but regular JavaScript DOM objects can:
var mySpanString = $('span').get(0).outerHTML;
As others have stated, you can use outerHTML or a clone -> append -> html ()
But here is another way to do this,
var nodeName = mySpan[0].nodeName.toLowerCase(); var outerHtml = "<"+nodeName +">"+mySpan.html()+"</"+nodeName +">";
Source: https://habr.com/ru/post/1436501/More articles:linear equation java - javaZF2: return JSON for Ajax call only - phppy-postgresql multithreaded problems - pythongtk - close window form with button in C - cCounting adjacent cells in a numpy array - pythonMVC3 Html.BeginForm () with optional HTML - asp.net-mvc-3Failed to load file or assembly "System.Net.Http, Version = 4.0.0.0" - asp.netboost :: algorithm - line splitting returns an additional token - c ++Equivalent to grep -v with git log pickaxe - gitCreating a virtual template in Java - javaAll Articles