javascript - elements attributes return "undefined" for no reason -


i have piece of code:

function removefromcart(id) {      var items = document.getelementbyid("overview").children;      for(var = 0; < items.length;i++)     {         console.log(items[i]);         console.log(items[i].value);     } } 

the first log returns actual element:

<div class="overview-item" value="0" data-total="5">1x item name - 5€<button onclick="removefromcart(0)"></button></div> 

but second log returns

undefined 

why doing this? why isn't returning value of elements "value" attribute?
, how go fixing it?

<div> element nodes don't have "value" property. that's <input> , other form controls. if put "value" attribute in tag, have use .getattribute() fetch value.

depending on you're trying do, can inspect children elements , check "nodetype" property know what/how access stuff.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -