Reputation: 2648
<input type="checkbox" class="check" value="true" name="1">
<input type="checkbox" class="check" value="true" name="2">
<input type="checkbox" class="check" value="true" name="3">
Now what I want is that get the checkbox in "check" class which has name:1, or 2 or 3
I tried below but not working
var me=1; // need to save it in a variable
$('.check[name=""+me]').prop("checked",true); // pay attention in +me
I it should work please let me know.Then i will look why it is not working.Thanks for having time on my issue.
Upvotes: 1
Views: 42
Reputation: 5348
$(".check")
.filter(function(){
return $(this).attr("name") == "1";
})
.attr("checked", true);
Upvotes: 0
Reputation: 82231
Try this:
var me = 1;
$('.check[name='+me+']').prop("checked",true);
or
$('.check[name="1"]').prop("checked",true);
Upvotes: 1
Reputation: 318172
You're almost there
var me = 1;
$('.check[name="'+me+'"]').prop("checked",true);
Upvotes: 2