Getting value of span with JavaScript
All text within elements is in the form of #text nodes, these are accesible via the DOM.
First you find the span element.
Code:
var myspan = document.getElementById(’myspan’);
Assuming there is nothing but text within it, we can get the text node like this:
Code:
var span_textnode = myspan.firstChild;
Then use the data property to get the actual text:
Code:
var span_text = span_textnode.data;
innerHTML and innerText are non-standard properties. The DOM method shown above is far superior and more robust as it works with the parsed DOM tree; rather than editing the in-memory source code which then has to be reparsed (less efficient and risking syntactic errors).
? It work prefectly in IE and Opera? and? also? Firefox.