I have problem with my jQuery code where my Firebug gives me warning: Selector expected.
Here is the code:
$("img[id$='_tick']").each(function() {
$(this).click(function() {
var tickIDFinder = $(this).attr("id");
var tickSection = tickIDFinder.slice(0,1);
var checkboxID = "\"input[id^='" + tickSection + "_checkbox_']\"";
var airTableID = "#" + tickSection + "_airline_table tr";
$(checkboxID).each(function() {
if ( $(this).is('checked') ) {
alert("Checkbox is Checked.");
}
$(this).attr('checked','checked');
});
});
});
What I’m trying to do is write a jQuery to allow users click a link (as an image). When the users click on this image, it will then ‘checked’ all the checkbox specified. It will then I got the Selector expected warning from my Firebug.
The jQuery itself is working as I expected. I just want to try to fix warning.
Anyone can help? I would really appreciate it.
Thank heaps for your thought.
In addition to the other answers, this can be simplified even further, like this:
A few things here:
.each(), just.click()and it’ll bind to all of them.this.idandthis.checkedcheckboxIDhad extra quotes, remove themLikely without the debugging, it’s even simpler, as
.attr()works on multiple elements as well: