I'm trying to pass in the value of a variable to a jQuery selector but I can't seem to get it right. Here is what I'm working with:
var state = $("<%= @state %>").selector;
that captures this value -> "pending"
I'm trying to pass that value into this selector:
$(".snitches-index-header + .tags-column .#{state}_count")
As you can see I'm trying to pass the string into the jQuery selector. But this is not working as I expect. What am I doing wrong so that the selector would read:
$(".snitches-index-header + .tags-column .pending_count")
but obviously use the variable state instead of pending
?
You can concatenate the variable with the string:
$(".snitches-index-header + .tags-column ." + state + "_count")
If you are trying to use a Template literal then you need to use backticks and the dollar sign not #
:
$(`.snitches-index-header + .tags-column .${state}_count`)
its just basic js syntax issue.
$(".snitches-index-header + .tags-column ."+state+"_count");
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