Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript textContent is not working in IE8 or IE7

I need to add 2 cell content of a table and display it. Below JavaScript command works fine in chrome or IE10. But not working in IE8 or 7.

parseFloat(document.getElementById("total").textContent).toFixed(2);

It results,

NaN

Could you please tell me what is the equivalent command in IE7 or IE8 to read cell content of a table and convert it to float then add..

like image 890
logan Avatar asked Aug 20 '13 03:08

logan


People also ask

Is textContent faster than innerHTML?

textContent uses straight text, does not parse HTML, and is faster. innerText Takes styles into consideration.

Is textContent same as innerHTML?

textContents is all text contained by an element and all its children that are for formatting purposes only. innerText returns all text contained by an element and all its child elements. innerHtml returns all text, including html tags, that is contained by an element.

Is textContent better than innerText?

textContent gets the content of all elements, including <script> and <style> elements. In contrast, innerText only shows "human-readable" elements. textContent returns every element in the node. In contrast, innerText is aware of styling and won't return the text of "hidden" elements.

What is textContent JavaScript?

In JavaScript, there are various properties that can be used to access and modify the content of html tags i.e. textContent, innerText, and innerHTML. The textContent property returns all the text contained by an element/node and all of its descendants including spaces and CSS hidden text, except the tags.


1 Answers

textContent is not supported by IE7/8. The latter has a different property called innerText which returns the text contents of a DOM node.

Here is how to use both:

var text  = e.item.textContent || e.item.innerText;
alert(text);

NOTE: e is html element

like image 84
Kiran Avatar answered Nov 04 '22 23:11

Kiran