Deborah Deborah - 3 months ago 7
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?


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.