javascript - getting an div ID, passing to a variable, then unhiding that div using jquery -
i'm trying capture button id , pass function associates div has same value. want dynamically have jquery change css on div.
everything works (i can dynamically create div id , show it, won't background yellow.) in long run want have "display: none" appear click on provided buttons.
here's html:
<div class="parent" id="level_0">intro level <br></br> <input type="button" id="level_1a" value="choice a" onclick="set_path(this.id);"> <input type="button" id="level_1b" value="choice b" onclick="set_path(this.id);"> <br></br> <div class="child" id="level_1az">this level 1 </div> <div class="child" id="level_1bz">this level 1 b </div> </div> <div id="fill-in"></div> here's js:
function set_path(clicked_id) { var divx = ('#' + clicked_id); var divid = "'"+divx+"'"; document.getelementbyid('fill-in').innerhtml = divid; $(divid).css("background-color", "yellow"); }; you can see code here: http://codepen.io/cunyj/pen/qdryxe/
you're not using jquery library in codepen`
your level ids have additional
"z"level_1azmight want to:
function set_path(clicked_id) { var divx = ('#' + clicked_id); $('fill-in').html( divx ); $(divx+'z').css("background-color", "yellow"); // use 'z' } function set_path(clicked_id) { var divx = clicked_id; document.getelementbyid('fill-in').innerhtml = divx; var level = document.getelementbyid(divx +'z'); // use 'z' level.style.backgroundcolor = "yellow"; }
Comments
Post a Comment