Good Day
I want to add a variable into a jQuery selector, but the syntax is wrong:
var c = $(this).attr('class');
if ($('#articleThumb ul li img').hasClass(c)) {
$('#articleThumb ul li img.'+c').clone().appendTo('#articleFeatured');
}
the class
img.class is a variable and not a constant like img.birds for example...
Thank you
Your quotes are off, notice the stray one after c
. It should be:
$('#articleThumb ul li img.' + c)
You can simply concatenate the variable with selector string. Remove the extra single quote at the end of c in selector.
Change
$('#articleThumb ul li img.'+c')
To
$('#articleThumb ul li img.' + c)
Looks like you're adding an additional '
$('#articleThumb ul li img.' + c)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With