javascript - Get id attribute from a node in nodelist -
i have got nodelist using document.getelementsbyclassname method in javascript. check if first node has children , if not return document.getelementbyid nodes id. unsure of how id node list.
var columns = document.getelementsbyclassname('.col-md-4.column'); if (countchildren(columns[0].childnodes) == 0) { return document.getelementbyid(columns[0].) //not sure goes here }
if have dom node, has id
property, can't use getelementbyid
property
var columns = document.queryselectorall('.col-md-4.column'); if ( countchildren(columns[0].childnodes) == 0 ) { return columns[0].id; }
note getelementsbyclassname
takes classes without period, better support might use queryselectorall
Comments
Post a Comment