I have two sets of items, one that I have my jQuery treating the class as a clickable item and grabbing the id, it the performs a task upon the other set of corresponding items that has a different class but the same id.
Right now I’ve got it alerting me of the id like so:
$(".class1").click(function(){
alert(this.id);
});
Can I do the following to have it change the height of the correspond item:
$(".class1").click(function(){
$(".class2".this.id).animate({width:"400px", opacity:1}, 400 );
});
Edit (15:08 EST)
I actually have two separate DIVs acting on one another. I didn’t know about the ID uniqueness rule, can I do the same thing by using a subclass in the second DIV like so?
<div class="class1">Click Me!</div>
<div class="class2 class1">Stuff happens here</div>
$(".class1").click(function(){
$(".class2 "+this.class).animate({width:"400px", opacity:1}, 400 );
});
Yes, but you have a syntax error in your code. Here is it fixed:
Technically speaking though, it’s redundant (and slower!) to specify the ID inside the context of a class since IDs are (supposed to be) unique.
In fact, you can even just get the jQuery object from a DOM object like so: