includes() not working in IE
The issue is because includes()
is unsupported in all versions of IE: MDN Reference
Instead you can use the much more widely supported indexOf()
:
var href = $(this).attr('href');
if (href.indexOf('#') != -1) {
// action
}
You could also prototype this to add the includes()
method to IE:
String.prototype.includes = function(match) {
return this.indexOf(match) !== -1;
}
includes
is not supported in Internet Explorer (or Opera)
Instead you can use indexOf
. #indexOf
returns the index of the first character of the substring if it is in the string, otherwise it returns -1. (Much like the Array equivalent)
Try the following:
var href = jQuery(this).attr('href');
if(href.indexOf('#') > -1) //this will true if the string contains #
{
// action
}
This is supported by all browsers. This is a good read for your issue :)