Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
includes() not working in IE

I am using the following code. It works perfectly in browsers such as Chrome, Firefox or Edge. However when I check in IE11 it does not work and breaks all the functionality.

var href = jQuery(this).attr('href');
if (href.includes('#')) {
  // action
}

I think includes() does not work in IE11. Is there a solution for this?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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;
}
over 4 years ago · Santiago Trujillo Report

0

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 :)

over 4 years ago · Santiago Trujillo Report

0

Firstly you can check. Because IE does not support includes: MDN Reference

You can use like this. Yes, I know this is VanillaJS way. If you work cross browser use this way to avoid errors.:

var btn = document.querySelector('button')
var link = document.querySelector('a')
var isIE = window.navigator.userAgent.indexOf('Triden') > -1

btn.addEventListener("click", function() {
	
  var isHash = (!isIE) ? link.href.includes('#') : link.href.indexOf('#') > -1
  alert(isHash)
}, false)
<button>Control hash</button>
<hr />

<a href="http://somesite.com/#/GetUsers">Users</a>

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!