getelementsbyclassname - Accessing a child class from parent class javascript -


this question has answer here:

<td <td class="upgrade_building b_wall">     <a href="#" class="building_tooltip d_0" tooltip="<span class='icon header wood'></span> 801 <span class='icon header stone'></span> 1846 <span class='icon header iron'></span> 320<br />población: 5<br />tiempo de construcción: 3:12:01">10     </a> </td> 

i'm making script perform autoclick on element "building_tooltip d_0" contained within "upgrade_building b_wall" tried code:

javascript:var list = document.getelementsbyclassname("building_tooltip d_0"); (var i=0; i<list.length; i++) list[i].click(); 

but in dom of page there other elements "building_tooltip d_0" not want run, want run "upgrade_building b_wall".

can me?

you can use document.queryselectorall, supported in modern browsers:

var list = document.queryselectorall(".upgrade_building.b_wall > .building_tooltip.d_0"); (var i=0; i<list.length; i++) {     list[i].click(); } 

alternatively can use if statement check node has correct parent before perform click on it:

var list = document.getelementsbyclassname("building_tooltip d_0"); (var i=0; i<list.length; i++) {     if (list[i].parentnode.classname === "upgrade_building b_wall") list[i].click(); } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -