This is an easy bit of coding, but something’s there that i am doing wrong.I just can’t figure it out.
#div {
display:none;
}
JS:
function show() {
var class = 1;
$("#div." + class).show("slow");
}
HTML:
<div id="div" class="1">John</div>
<div id="div" class="2">Tanner</div>
<input type="button" onclick="show()" />
Here I am trying to ‘show()’ a div of specific class.
The problem is, this code works fine for class="1". But when I change var class to 2, it stops working.
A class can’t be just a number. Rename the class to
$("#div." + "name"+class)