Reputation: 657
I am trying to select a group of elements with a similar class. and then filter the selection by the element id. Is there a better way to go about this?
Then using that same id, I want to do something to a element set up with the same show entitcal class
$('ElementClass-1').attr('ElementId-1');
$(this).hover(function(){
..do stuff
});
});
<a class="ElementClass-1" id="ElementId-1">hover me</a>
<a class="ElementClass-1" id="ElementId-2">hover me</a>
<a class="ElementClass-1" id="ElementId-3">hover me</a>
<div style="display:none; class="ElementId-1">show me</div>
<div style="display:none; class="ElementId-2">show me</div>
<div style="display:none; class="ElementId-3">show me</div>
Upvotes: 0
Views: 2324
Reputation: 1601
Can you add a class with the same name for all the elements just for selecting? something like
class="ElementSelector"
later you can use that class for the selection
Upvotes: 0
Reputation: 79830
Try something like below,
$(ElementClass).each(function () {
$('.' + this.id).<your_function>();
});
Upvotes: 1
Reputation: 1164
Use jquery's multiple attribute selector http://api.jquery.com/multiple-attribute-selector/
the first attribute is going to be "class" and the second attribute is going to be "id"
Upvotes: 0