javascript - click a button based on div id and value with a script -
i have following situation. need simulate button click on off value button under div based on id
<div id="devicecontrols1"> <button value="off">off</button> <button value="on" class="active">on</button> </div> <div id="devicecontrols2"> <button value="off">off</button> <button value="on" class="active">on</button> </div
i know not valid code in other words id like:
document.getelementbyid('devicecontrols2').getelementsbyvalue('off').click();
im not sure how use javascript obtain result
using javascript, try this:
var buttons = document.getelementbyid('devicecontrols2').getelementsbytagname('button'); (var = 0; < buttons.length; i++) { if (buttons[i].value == 'off') { buttons[i].click(); } }
using jquery (since have tagged):
$('#devicecontrols2').children('button[value="off"]').click();
Comments
Post a Comment