I've got an ajax function that gets some values based on the selected value in a dropdown. I'm trying to enable/disable some fields based on a substring. I found 'contains' to work in firefox, but testing in chrome and safari tells me that the object 'has no method contains'
if ($d.attr("embed").contains('$var_2$')) {
//do something
} else {
// do something else
}
Is there an alternative to contains that will work in all browsers?
what you're using there is String.contains
, not jQuery.contains
. this is because you're using the function on .attr
s return-value, wich is a String, not a jQuery-Object.
to use jQuery.contains()
(wich works cross-browser), you could do this instead:
$d.contains('$var_2$')
but note that this won't only search in the specified attribute but the whole element instead.
so what you most likely want to do is using String.indexOf()
(wich also works cross-browser):
$d.attr("embed").indexOf('$var_2$') != -1
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