Hi all,
I am using jQuery to grab the ID of a DIV Tag and then add some CSS style to the DIV
accordingly.
I am new to jQuery, and I am not sure if this is a good way to do it:
JavaScript:
$(".myClass").click(function(e){
var whatid = $(this).attr('id');
var whichDiv = "divName"+whatid;
("$(\"#"+whichDiv+"\")").addClass();
}
HTML:
<div id="myTest1" class="myClass">
Helloworld I am new to JQuery 1
</div>
<div id="myTest2" class="myClass">
Helloworld I am new to JQuery 2
</div>
Please advise.
What if I changed the code in this way:
JavaScript:
$(".myClass").click(function(e){
var whatid = $(this).attr('id');
var whichDiv = "divName"+whatid;
("$(\"#"+whichDiv+"\")").addClass();
}
HTML:
<div id="1" class="myClass">CLick here 1</div>
<div id="2" class="myClass">CLick here 2</div>
<div id="myTest1">
Helloworld I am new to JQuery 1
</div>
<div id="myTest2">
Helloworld I am new to JQuery 2
</div>