function dowork()
{
$(".wrappedElement").removeClass("wrappedElement");
$(".wrappedElementout").removeClass("wrappedElementout");
var a=$("div#DepPart select option:selected").val();
$("div#TestPart select option[value^=a]").addClass("wrappedElement");
$("div#TestPart select option[value!=a]:not(div#TestPart select option[value^=a])").addClass("wrappedElementout");
}
In this function var a gets the value (a=”HMT”) in string format and when i uses this value as part of the jQuery selector it does’t work for some reason. Can anybody suggest what the solution may be?
The problem is that you are not referencing the variable
aanywhere, you are simply including the letter “a” in your string. You need to concatenate the value from the variableawith the string you are using as a selector:Note also that jQuery selectors with the square bracket attribute equals something syntax expects the something to be in quotes (which I’ve included above).
With your example value of
a, “HMT” the first selector will end up looking like the following after the concatenation:(And similar for the other line.)