html - Extracting value from a div sent in to javascript -
im attempting id of specific box call.
<div id="box1" onmouseover="transition(box1)" onmouseout="detransition(box1)"> <div class="box1-smallbox"> </div> function transition(prop){ document.getelementsbytagname(prop + "-smallbox").style.marginleft = x; }
i want prop = box1. easy system can used 10 or 20 boxes.
thanks in advance!
without jquery, javascript:
<div id="box1" onmouseover="transition(this.id)" onmouseout="detransition(this.id)"> <div class="box1-smallbox">aaa</div> </div> <div id="box2" onmouseover="transition(this.id)" onmouseout="detransition(this.id)"> <div class="box2-smallbox">bbb</div> </div> <div id="box3" onmouseover="transition(this.id)" onmouseout="detransition(this.id)"> <div class="box3-smallbox">ccc</div> </div> <script type="text/javascript" language="javascript"> function transition(prop){ var els = document.getelementsbytagname("div"); for(var i=0;i<els.length;i++){ if(els[i].classname==prop+"-smallbox"){ els[i].style.marginleft = 200; } } } function detransition(prop){ var els = document.getelementsbytagname("div"); for(var i=0;i<els.length;i++){ if(els[i].classname==prop+"-smallbox"){ els[i].style.marginleft = 0; } } } </script>
Comments
Post a Comment