The Java script is currently incompatible with Firefox, Internet Explorer 7, and Internet Explorer 6

Issues have been identified with the JavaScript code when running on Firefox, IE7, and IE6 (IE8 worked after applying getElementsByClassName.polyfill.js). Can anyone pinpoint the problem in the script that is causing these browsers to malfunction? (Chrome and Safari were functioning properly before the polyfill.js was added.)

The purpose of this JavaScript is to allow users to open and close multiple levels of categories by clicking.

/*------------------------------------------
Open or close the specified node.
------------------------------------------*/
function openOrClose(tgt){

// Make the list visible if it is currently hidden.
if(tgt.style.visibility == "hidden"){
    tgt.style.display = "block";
    tgt.style.visibility = "visible";

    tgt.style.height = "auto";
    tgt.style.paddingTop = "0.25em";
    tgt.style.lineHeight = "1em";
    tgt.style.opacity = 1.0;

}
// Hide the list if it is not hidden.
else{
    tgt.style.display = "none";

    tgt.style.visibility = "hidden";
    tgt.style.height = "0px";
    tgt.style.paddingTop = "0";
    tgt.style.lineHeight = 0;

    tgt.style.opacity = 0;
   }
   }

   /*------------------------------------------
   Open the list
   ------------------------------------------*/
   function listopen(lv, num){
   var tgt = document.getElementsByClassName("level" + lv)[num];

    // Search for the next level to open the next level list.
   for(var i=0; i < document.getElementsByClassName("level" + (lv+1)).length; i++){
    var next_tgt = document.getElementsByClassName("level" + (lv+1))[i];
   
    if (next_tgt.parentNode == tgt || next_tgt.parentNode.parentNode == tgt){
        openOrClose(next_tgt);
    }
    }

    // Change the shape of the button displayed in the next level.
    for(var i=0; i < tgt.childNodes.length; i++){
    var next_tgt = tgt.childNodes[i];
  
    if(next_tgt.tagName == "UL"){
        if(next_tgt.style.height == "0px"){
            if(event.srcElement.parentNode.className == "category_header plus"){
                event.srcElement.innerText = '?';
                event.srcElement.parentNode.className = "category_header minus";
            }
            next_tgt.style.height = "auto";
        }
        else{
            for(var i=0; i<next_tgt.parentNode.childNodes.length; i++){
                if(event.srcElement.parentNode.className == "category_header minus"){
                    event.srcElement.innerText = '+';
                    event.srcElement.parentNode.className = "category_header plus";
                }
            }
            next_tgt.style.height = "0px";
        }
        }
        }
       }

     /*------------------------------------------
    Set up the click event
    ------------------------------------------*/
     function setclickevent(tgt, lv, num){
     
      if(lv!=1){
    tgt.style.visibility = "hidden";
    tgt.style.display = "none";
    tgt.style.height = "0px";
    tgt.style.lineHeight = 0;
    tgt.style.paddingTop = 0;
    tgt.style.paddingBottom = 0;
    if(tgt.parentNode.tagName == "UL"){
        tgt.parentNode.style.height = "0px";
        tgt.parentNode.style.margin = "0";
        tgt.parentNode.style.padding = "0";
        tgt.parentNode.style.border = "none";
        }
        }
        var hasLink_flg;
         if(tgt.childNodes.length){
    for (var j = 0; j < tgt.childNodes.length; j++) {
      
        if(tgt.childNodes[j].tagName == 'A'){
            tgt.setAttribute('onclick', 'location.href="' +  
     tgt.childNodes[j].getAttribute('href') + '"');
        }
      
        else if(tgt.childNodes[j].tagName == 'UL'){
          
            var linkObj = document.createElement("a");
            linkObj.innerText = '+';
            tgt.childNodes[0].className="category_header plus";
            tgt.childNodes[0].appendChild(linkObj);
            j++;
            linkObj.parentNode.setAttribute('onclick', 'listopen(' + lv + ',' + num + ')');

           
             break;
          }
         }
         }
        }

       
      // Initialization - Add click events to all nodes with the class "level?"
      function initCategoryList(){
      var lv = 0;
    
         while(document.getElementsByClassName("level" + (++lv)).length){
        
        for (var i = 0; i < document.getElementsByClassName("level" + lv).length; i++) {
         
        setclickevent(document.getElementsByClassName("level" + lv)[i], lv, i);
             }
           }
         }

Answer №1

From my understanding, tgt.style.display = "none"; //works well with IE6,7,8,9,10,ff,CHORME However, tgt.style.opacity = 0; //does not work properly with IE8.

I recommend utilizing jQuery and writing jQuery code to eliminate browser inconsistencies.

such as: $(tgt).hide or: $(tgt).css({ display: "none", height: "0px" });

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

Issue with event handler not being connected following Ajax update, an element in the dom is not recognized (Internet Explorer

Issue: Newly inserted DOM elements are not being correctly linked, and the function deletepost is not triggering. This problem only occurs on Internet Explorer and with new elements that are added to the DOM. $(function(){ $('#postentry' ...

Guide to incorporating vertical scrolling for a grid of items in Material UI

Is there a way to implement vertical scrolling in a grid container so that when the height of components exceeds a certain maximum, they can be scrolled through vertically? ...

Adding multiple instances of a JPanel class without replacing them

Currently, I am facing an issue where I have created a class that extends JPanel (shown below) and I am attempting to add multiple instances of this class to another JPanel. public class DOBGui extends JPanel { private static String dayList[] = {bunch o ...

Is there a way for me to hear events from different applications?

Exploring the development of an electron app. Interested in incorporating an event listener into external applications to generate a console message based on certain actions. For instance, monitoring the opening of a new tab in Chrome and displaying a me ...

Determine the distinct elements in an array using JavaScript/jQuery

I have incorporated Gridster widgets into my webpage, each with a button that turns the widget's color to red when clicked. Upon clicking the button, the parent element is also added to an array. My main goal I aim to have the parent element added t ...

Implement basic user authentication using jQuery and Ajax

I'm currently working on setting up a basic authentication system through the browser, but I'm facing some challenges. If I remove this script, the browser's default authentication will take over. However, I want to inform the browser that ...

"Encountered an error: Unable to access property 'fn' on an undefined object within the Wordpress

I attempted to recreate the steps outlined in this blog post Create A Realistic Self-solving Rubik's Cube With Three.js on a Wordpress page. However, I encountered the following error Uncaught TypeError: Cannot read property 'fn' of undefine ...

gulp.watch executes tasks without following a specific sequence

Objective Develop a gulp.watch task to execute other tasks in a specific sequence Why this is unique While many have referred me to How to run Gulp tasks sequentially one after the other, my query differs as it pertains to using gulp.watch instead of gu ...

What is the best way to prevent one react audio player from continuing to play when starting another?

I'm struggling to implement state tracking to determine which song is currently playing. I'm unsure about the parameters to pass into the React Audio Player and where to set the state. Can anyone help with this? This is the code for the entire co ...

The code inside the if statement is somehow executing even when the if statement is not true

Similar Question: Issue with jQuery function running at inappropriate times I've spent several hours trying to figure out why my function isn't working properly. I have a function inside an if ($window.width() < 1000) statement, but it se ...

Revamp the UI Framework's CSS to accommodate the latest Web Components

I've implemented Grommet as the UI Framework for my React page. However, I encountered a situation where certain web components, like a web chat control, are not covered by Grommet's CSS. What is the simplest way to style these additional web com ...

Mastering the perfect synchronization of useState and useEffect

I'm struggling with comparing the values of two inputs, specifically for a password and confirm password input in a form. While using onChange in React useState to render the DOM is straightforward, I know that I should be utilizing useEffect as well ...

Verify user credentials during login in a React application

My current challenge involves setting up a hardcoded authentication in React for user login using a form. Despite meeting the requirements for the "if" statement, it always returns the "else" statement. I am attempting to pass both the handleSubmit functi ...

Attempting to develop a straightforward JavaScript presentation display

The slideshow will cycle through six images named 1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg, and 6.jpg var showarray = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"]; var i = 0; for( i = 0; i < 6; i++) { // Is there a way to pause the script for two ...

What causes the disappearance of an entire component's code?

Can someone please explain what just happened here? Is it a problem with VS Code or is it a hardware issue? Sometimes my HDD appears to be undetected (not sure if it's due to malfunction of the HDD or something else). https://i.sstatic.net/BVCNm.png ...

The left side of the page is anchored with text content while an engaging carousel occupies the right half

Looking to create a section on the website that remains fixed while a carousel scrolls vertically. Once you reach the final slide, scrolling will continue on the page rather than changing the carousel slide. Want it to function similarly to the Creative s ...

What could be the reason for event.stopPropagation() not functioning properly with a switch statement

Could you please explain why the function event.stopPropagation() is not working on the switch element? Whenever I click on the switch, it prints the console log for the switch. However, when I click on the surrounding area (row), it logs the row event in ...

Switch the hover effect to be activated by clicking

Recently, I discovered an incredible plugin created by the talented developer janko. It has been a fantastic addition to my project. The only issue I've encountered is that I do not want the default hover style. Is there a way to transform it into a ...

Is it possible to implement a delay period or prompt for user confirmation before the transition can be repeated?

When using CSS to code for an image or box to move when hovered over, there can be unexpected results. If the mouse is positioned within the click area at the beginning of the transition but not at the end, the effect may repeat indefinitely and stutter if ...

Can we stop Angular components from being destroyed during navigation?

Consider the scenario where I have two distinct Angular 2 components known as ComponentA and ComponentB. My goal is to navigate from ComponentA to ComponentB and then return to ComponentA without needing to reinitialize it. In the current setup of Angular ...