[jQuery] Using variables in an Attribute filter
I am trying to do something that seems very simple, but can not get to
work! Basically, I want to find an element whose ID equals a certain
value, as represented by a variable. The variable is derived from a
dropdown list. Here is my code:
$(document).ready(function(){
$("select").change(function() {
var myClr = $("select").val();
$("p[id=myClr]").addClass("bold"); //this is the line giving me
trouble
});
});
I am wondering if it is legal to use a variable within the filter - if
I replace it with an actual ID value it works fine, but when I
substitute the variable name nothing happens.
I am sure I am doing something dumb! Thanks for any suggestions.
Roi