I have one problem with jquery contains. It work perfect on firefox.
This is my code.
$("input[data-height='cm']").blur(function(){
var text = $(this).val();
if($(this).val().length > 0) {
if(!$(this).val().contains("cm")) {
$(this).val(text + " cm");
}
}
});
on chrome it give error
Uncaught TypeError: $(...).val(...).contains is not a function
How can I fix it please help.
Thank you.
There is no such method as contains
in Chrome. Instead, you should better use indexOf
:
// Instead of...
if ($(this).val().contains('cm')) { /* val() contains 'cm' */ }
// ...do this:
if ($(this).val().indexOf != -1) { /* val() contains 'cm' */ }
Please note that indexOf
returns -1 if occurence is not found in string and >= 0 if occurence is found.
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