So, if I have a table with the class name site-table. In one of the table cells, there is a text 'Appliance' , then I can do this:
$(".site-table")
(".site-table:contains('Appliance')");
Now, say I have a variable called the_table:
$the_table = '.site-table'
when I replace the ".site-table" with $the_table variable, I get errors:
$("$element:contains('Appliance')");
jquery-3.1.1.slim.min.js:2 Uncaught Error: Syntax error, unrecognized expression: $element:contains('Appliance')
at Function.ga.error (jquery-3.1.1.slim.min.js:2)
at ga.tokenize (jquery-3.1.1.slim.min.js:2)
at ga.select (jquery-3.1.1.slim.min.js:2)
at Function.ga [as find] (jquery-3.1.1.slim.min.js:2)
at r.fn.init.find (jquery-3.1.1.slim.min.js:2)
at new r.fn.init (jquery-3.1.1.slim.min.js:2)
at r (jquery-3.1.1.slim.min.js:2)
at <anonymous>:1:1
So, then the question is how to pass filters to variables in jQuery. This is particularly useful when using a generic function rather than coding for each individual repetitive case.