Hey,
I am trying to make a lift where every button is object of a button class.
Now i want to call the specific button in my for loop when a button is pressed.
I am using an associative array.
I know how to get the button id, but i have no idea how to use it in my for loop.
Sorry if this is a stupid question, tried searching but probably used the wrong words.
This is my html.
PHP Code:
<body>
<button id="btn0" class="lift_btn">0</button>
<button id="btn1" class="lift_btn">1</button>
<button id="btn2" class="lift_btn">2</button>
<button id="btn3" class="lift_btn">3</button>
<button id="btn4" class="lift_btn">4</button>
<button id="btn5" class="lift_btn">5</button>
<div id="lift" style="position: absolute; top:200px; left:0px; background:#98bf21;height:150px;width:100px;"></div>
</body>
This is my js:
PHP Code:
var myHeight = [100, 200, 300, 400, 500, 600];
var btnArray = new Array();
btnArray["btn0"] ="0";
btnArray["btn1"] ="1";
btnArray["btn2"] ="2";
btnArray["btn3"] ="3";
btnArray["btn4"] ="4";
btnArray["btn5"] ="5";
btnArray["btn6"] ="6";
$(document).ready(function() {
console.log('test');
$(".lift_btn").click(function(){
console.log(this);
console.log( $(this).attr("id") );
for (var i = 0, btnArray[i] == "id", i++ )
$("#lift").animate({top: myHeight[i] ,width: "+=0",opacity:0.4},"slow");
});
});