How to place a variable value within a selector? (Dynamic ID values)
Hello all.
I have the following that works just fine. If the div ID includes the string "targetDiv" then alert.
- $("div[id*='targetDiv']").click(function(){
- alert("found the div");
- });
Now I would like to make the string for which it searches dynamic. I tried this
- var idTarget = "targetDiv";
- $("div[id*=idTarget]").click(function(){
- alert("found the div");
- });
I am replacing the hardcoded string value of "targetDiv" with the variable of idTarget whose value is "targetDiv"
Is this possible? What is the syntax?
Thanks so much.
Rich