window.something.updateStatus = function(theName) {
$('#myTable').children('tr').remove(":contains('theName')");
};
Obviously the above does not work because it is looking for a string called "theName" in any in myTable.
What I'd like to do is pass in theName's Value to the contains.
How do I evaluate this expression?
Thanks.
Yes, it is possible to pass a variable into a jQuery attribute-contains selector. The [attribute*=value] selector is used to select each element with a specific attribute and a value containing a string.
It's jQuery equivalent would be something like this: $('button'). on('click', myFunction); Passing an argument to that function would then be something like this: $('button'). on('click', myFunction('test')); .
The :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element. This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).
This is untested, but should work:
window.something.updateStatus = function(theName) {
$('#myTable').children('tr').remove(":contains('" + theName +"')");
};
Essentially it removes the variable theName
from the string, but still quotes that value (once the variable's interpolated), which is why there's an opening, and closing, '
either side of the variable and +
concatenation operators.
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