$(".gl").hover(function() {
$('select[name="' + $(this).attr('name') + '"]').removeClass("gl").addClass("glHover");//Occurs when hovering over
}, function(){
//Occurs when hover is done
$('select[name="' + $(this).attr('name') + '"]').removeClass("glHover").addClass("gl");
});
This is my code, basically when someone hovers over any class that is gl, it needs to find all elements with the name matching its own name, this is not working for me though and I’m pretty new to jquery so I’m not sure how to pull this off
Edited the code above, now its still not working, this is why my html looks like(Approx):
<table><tr>
<td class='gl' name='07/25'></td>
</td></table>
Update
$('td.gl').hover(function() {
$('select[name="'+ $(this).data('name') +'"]').toggleClass('gl glHover');
});
and
<td class='gl' data-name='07/18'></td>
Still not working
Try:
Your element declaration was invalid as you were missing a
+for concatenation, which in this case is for substituting the element’s name attribute, and your quotes are incorrect. I switched to single quotes since you are using double-quotes for the name attribute and the syntax was invalid.Update: It seems that you want to select any element type with a name corresponding to the name of the hovered element. Currently the usage of
select[...]looks for aselectelement. I would suggest you use aclassattribute with a value for the correspondingnameto link your elements together and then you can reference those elements with aclassthat represents thatnameattribute..In this case try the following: