Deborah Deborah - 1 year ago 114
HTML Question

javascript get value of a field in an HTML object

In console.log I have an HTML object like this...

enter image description here

If I wanted to make a javascript to access and display the value of "name" from the HTML object (not by another method) like so...

<script type="text/javascript">
var getName = how to get it?

... how would I do it?

What if "name" was nested in something like "attributes: NamedNodeMap"? How would I get a nested value?

Answer Source

Use dot "." to get to all values - so if it were

Object {
  Name: value

You would use var getName =; to get the value.

And you would have to find out the names of your objects in order to Access them. In your case the object seems to have an _id attribute so you can find it through that perhaps:

<script type="text/javascript">
function FindByAttributeValue(attribute, value)    {
  var All = document.getElementsByTagName('*');
  for (var i = 0; i < All.length; i++)       {
    if (All[i].getAttribute(attribute) == value) { return All[i]; }

var objectToFind = FindByAttributeValue("_id","zr9Gk...");//put in the ID here
var getName =;

I got the function from here.

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