Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't jQuery accept this string?

Tags:

jquery

When I run this function:

onUnCheck: function(el) {
var thenames = "icon-"+el.find("label:first").text().replace(/ /g,'').toLowerCase();        
alert(thenames);            
$("'."+thenames+"'").hide("fast");
}

I generate a string. I can see in the alert() that it is indeed the correct string. Example:

icon-jira

But when I pass the string in as a jQuery selector it does not work.

I know the function's logic is sound because pasting in the result of my alert() makes it work.

Why won't jQuery accept my string?

like image 820
Joel Crawford-Smith Avatar asked Jul 01 '26 11:07

Joel Crawford-Smith


1 Answers

$('.'+thenames).hide("fast");

This will look for ".icon-jira." You were looking for "'.icon-jira'" which adds the quotes to the selector.

like image 127
Gazler Avatar answered Jul 03 '26 01:07

Gazler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!