Mntfr Mntfr - 1 year ago 71
HTML Question

Stringify in javascript is returning an empty value

So I have the following code

var email = row.cells[2];

and that returns
as an object I think however I need that value as a string in order to remove the
I some websites says that I can use JSON.stringify but when i do it like that it returns
anybody knows why?.

Answer Source

The value that is returned is not just a normal JavaScript object, it's a special one. It is a DOM node, or more specifically a DOM element. It is the way the page is represented in JS.

Because of this, JSON.stringify() returns {}. Luckily, DOM elements have their own way of getting contents. To get the text content of a DOM element, use .textContent. In this case, it would be

var DOM_Element = row.cells[2];
var email = DOM_Element.textContent

Consider also innerHTML

var email = row.cells[2].innerHTML

Credit to @vlaz's comment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download