In a userscript i am getting [object XrayWrapper [object HTMLSpanElement]]
instead of html span tag.
How can i get the html tag like <span>--</span>
from this object?
The only difference is in the toString() method, which determines what happens when you try to turn an object into a primitive. You didn't state what you want to do, but if you're trying to turn a DOM object into HTML textual representation, then the outerHTML property should provide you with what you need.
var element = document.createElement("span");
element.appendChild(document.createTextNode("text"));
alert(element.outerHTML); // returns "<span>text</span>"
object.outerHTML
instead of object
in your code.
XrayWrapper
used by Greasemonkey to wrap around DOM Elements
is quite an imperfect wrapper, since it doesn't really support the innerHTML
getter/setter. I wrote you a simplistic innerHTML
implementation, call it like this: html(element)
. It ignores everything but elements, attributes and text nodes, but it should serve its purpose as long as the XrayWrapper
supports the other DOM attributes
I use in the function. pastebin.com/9LYPU67r
In the desired html element, just access the innerText property.
ex: element.innerText
<span<--</span>
in chrome but in firefox the output is shown in[object XrayWrapper [object HTMLSpanElement]]
object format