Reputation: 79
<a href="/JqueryTest/Delete/23" class="Delete-item">Delete</a>
if i use this JQuery code :
$('.Delete-item[href="/JqueryTest/Delete/23"]')
It work fine , but if i replace Value with my variable :
var MyVar= "/JqueryTest/Delete/23";
$('.Delete-item[href=MyVar]')
I have on error syntaxe, any help !
Upvotes: 0
Views: 2727
Reputation: 16835
try this
var MyVar= "/JqueryTest/Delete/23";
$('.Delete-item[href="'+MyVar+'"]')
Upvotes: 0
Reputation: 14039
myVar in [href=myVar] is a part of a string not a variable. So you need to say
$('.Delete-item[href="' + MyVar + '"]')
Upvotes: 0
Reputation: 11028
you have to concatenate the string in this way..
var MyVar= "/JqueryTest/Delete/23";
$('.Delete-item[href="' + MyVar + '"]');
Upvotes: 3
Reputation: 50019
It should be
var MyVar= "/JqueryTest/Delete/23";
$('.Delete-item[href="' + MyVar + '"]');
Concatenate the variable into the string
Upvotes: 2