Having difficulty getting the forEach method to function correctly on Internet Explorer

I successfully implemented an active/disable feature in my code that functions flawlessly on both Chrome and Firefox. However, I am encountering an error in IE specifically when using the forEach method.

Upon testing, the following error message appears when using IE: https://i.sstatic.net/GGVV8.png

In contrast, on Chrome and Firefox, the divs highlight the box correctly and display the corresponding box below. https://i.sstatic.net/aN8Mb.png

Below is the snippet of code that I am currently utilizing:

"use strict";

var tabButtons = document.querySelectorAll('.navlinksGP > a');

function enableTabButton(buttonId) {
tabButtons.forEach(function(btn) {
if (btn.id === buttonId) {
  btn.disabled = true;
  btn.style.background = '#eeaf00';
    btn.style.color = '#ffffff';
} else {
  btn.disabled = false;
  btn.style.background = '#ffffff';
    btn.style.color = '#eeaf00';
}
});
}
    enableTabButton('word');

var player = document.getElementById('player');

function wButton(element) {
  enableTabButton(element);
  if (element === "word") {
    player.innerHTML = "<h1 id=\"h1update\">Brand & Consumer Marketing</h1>";
  }
<div class="navlinksGP">
   <a id="word" onclick="wButton(this.id); window.location='#container'" href="#">BRAND & CONSUMER MARKETING</a>
</div>

The only issue I seem to be facing with IE is that the enableTabButton function does not work as expected.

Answer №2

Since you've used the "jQuery" keyword to tag your question, I'll provide a jQuery solution for you :-) Please take a look at the code below to see if it meets your requirements. It has been tested and works well in IE11 as well as modern browsers.

"use strict";

var tabButtons = document.querySelectorAll('.navlinksGP > a');

function enableTabButton(buttonId) {

  $(tabButtons).each(function() {

    //console.log($(this).attr("id"));

    if ($(this).attr("id") === buttonId) {
      $(this).prop("disabled", true);
      $(this).css("background-color", "#eeaf00");
      $(this).css("color", "#ffffff");
    } else {
      $(this).prop("disabled", false);
      $(this).css("background-color", "#ffffff");
      $(this).css("color", "#eeaf00");
    }

  });
}

enableTabButton('word');

var player = document.getElementById('player');

function wButton(element) {
  enableTabButton(element);
  if (element === "word") {
    player.innerHTML = "<h1 id=\"h1update\">Brand & Consumer Marketing</h1>";
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<div class="navlinksGP">
   <a id="word" onclick="wButton(this.id); window.location='#container'" href="#">BRAND & CONSUMER MARKETING</a>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoid page refreshing when retrieving data using PHP and AJAX

In my current program, I am able to add data and insert it into the database. However, I am looking for a way to automatically send this data to another page or browser without refreshing. I have two browsers open, so how can I submit the data to the other ...

Display a JSON encoded array using Jquery

Within an ajax call, I have a single json encoded array set: $var = json_encode($_SESSION['pictures']); The json encoded array is stored in a variable called "array" When I try to display the contents of "array" using alert, I get this respons ...

Provide a secondary element within a JSON object

I am struggling to extract a second integer variable from a JSON array. Currently, I can only retrieve the SP_NAME (which is a string) variable from the controller, but now I also need to pass the SP_ID so that jQuery knows where to place the information. ...

Having trouble integrating JQuery Mobile into ReactJS - Unable to find a solution for 'jquery-mobile' package

I've been attempting to integrate JQM into my ReactJS project. Here's what I'm doing to add it: npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="107a616575626950213e21213e21">[email protected]& ...

When viewing my website on a larger screen, my list items are floating to the left. However, on an extra small screen, the list items are stacking on top of each other. Is there a way

Creating a navbar with two li tags - one for language and another for currency. However, when the screen size is extra small, the li tags do not float left as intended, instead they stack on top of each other. How can this issue be resolved? Additionally, ...

The option value in mat-autocomplete is not displaying correctly on IOS devices

When I click on the first option in the dropdown menu, it does not display the selected option in the field. However, when I select the second option, then the value of the first option appears, and when I choose the third option, the value of the second o ...

Displaying jQuery AJAX response through the use of a PHP script as a middle

After setting up an AJAX request that functions correctly, I encountered a problem with retrieving and displaying the data received from the request. Here's the script in question: var input = $("#input").val(); $(".pure-button").click(function() { ...

Output undefined when displaying a JSON object using JavaScript

I received a JSON object that has the following structure: [ { "competition": { "name": "Premier League", }, "nextState": 1, "team_id": 1 }, { "competition": { "name": "Premier League", ...

Identifying a flaw in an HTML5 video

I am attempting to identify when an error occurs while playing an HTML5 video. Specifically, I am encountering a situation where I am trying to play an HLS video on a MAC (where "canPlayType" is at least "maybe"), but the video will not play for unknown r ...

Tips for sorting ng-Table using an array of numerous values

I am currently working on implementing angular-selectize.js (https://github.com/machineboy2045/angular-selectize) into my project. This will create a search box that allows for entering multiple values to filter all cells in an ng-Table without the need to ...

Having difficulty retrieving information from a json file with jquery

Currently, my project involves fetching information from a web API into a web application using JQuery. <script src="jquery-1.11.2.js"></script> <script src="jquery-1.11.2.min.js"></script> <script type="text/javascript"> $( ...

What is the process of uploading a video and showcasing it on an HTML page?

I have successfully uploaded images and displayed them on an HTML page. Now, I am looking to do the same for videos. Here is my current code: $('#addPhotosBtn').click(function() { $(this).parents().find('#addPhotosInput').click(); }) ...

Is it the same item in one situation, but a completely different item in another?

I am currently investigating the behavior of objects in JavaScript, particularly when it comes to copying one object onto another. It seems that sometimes they behave as if they are the same object, where modifying one also modifies the other. Many resourc ...

Tips for implementing a wait time for individual items in bee-queue

I've encountered an issue with the delayUntil function in the bee-queue library when creating a queue. await queue .createJob(process) .timeout(60 * 1000 * 2) .retries(2) .backoff('fixed', 60 * 1000) ...

Initialization of Angular provider $get is missing

Within my 'app.js' file, I have the following code that is used in my config to set up $navigationProvider.doSomething(). When running this code, Test1 and Test3 are alerted correctly, but I'm having trouble with getting my this.$get method ...

Make sure to close any existing Featherlight windows before trying to open another one

I'm setting up multiple featherlight instances when the page loads jQuery('.feedback').featherlight(jQuery( "#feedback-box" ), { closeIcon: 'close'}); jQuery('#imprint').featherlight(jQuery( "#imprint-box" ), { closeIcon ...

Steps to insert a personalized attribute into a TypeScript interface

UPDATED EXPLANATION: I'm fairly new to TypeScript, so please bear with me if this question seems basic. I'm working with an existing library (ngx-logger) that I don't want to or can't modify. My goal is to create a service that generat ...

Modifying property values using the onError event when encountering an error with the MUI DateTimePicker and

My goal is to set the 'myError' variable to true when MUI DateTimePicker throws an onError event, but for some reason it's not working. The code itself seems correct because if I replace () => {setValue({ ...value, ...

Resolving the Challenge of PHP's Unique MultiDimensional Arrays

Currently, I am extracting distinct values from my multidimensional array by employing the subsequent function: function unique_multidim_array($array, $key) { $temp_array = array(); $i = 0; $key_array = array(); ...

Retrieving PokéAPI image information

My goal is to display images from the PokéAPI on my app's homescreen when it is opened. However, I am facing a challenge where I need to call 30 different APIs in order to show 30 images. Calling these APIs one after another every few seconds seems l ...