Monday, 15 June 2015

javascript - Navigate up a node from document.getElementsByClassName -



javascript - Navigate up a node from document.getElementsByClassName -

is there way node or class above document.getelementsbyclassname example

<div class="a"> <div class="3"> </div> </div> <div class="z"> <div class="3"> </div> </div>

after doing

document.getelementsbyclassname("3")

is there way navigate class , z. if wanted alter color of entire , z class not 3 class.

i think looking .parentnode

for .parentnode, if using getelementsbyclassname (which returns array) have loop through array.

something along lines of (pardon if verbose, ios engineer trade):

var elementsofclassthree = document.getelementsbyclassname("3"); (var = 0; < elementsofclassthree.length; ++) { var parentelement = elementsofclassthree[i].parentnode parentelement.style.color = "blue" }

javascript

No comments:

Post a Comment