Having issues with the accordion function in IE7

Hey everyone, I'm completely new to jQuery and could use some help. This accordion feature works perfectly on Firefox and Chrome, but I'm running into issues with IE7. You can see the problem in action at this link: here.

Specifically, if you click on 222 and then on 999, it collapses back to 222 on IE7.

However, on Firefox it remains open as expected.

I would really appreciate any assistance or suggestions on how to fix this issue.

Below is the JavaScript code that I am currently using:

$(function(){
    $('.toc_content').find('li').each(function(){
        var li=$(this);
        if(li.find('> ul').length==1){
            li.addClass('collapsed').find('> a').click(function(e){

                var li=$(this).parent('li'), ul=li.find('> ul');

                ul.toggle();
                if(ul.is(':hidden')){
                    li.removeClass('collapsed').addClass('opened');
                }
                else{
                    li.removeClass('opened').addClass('collapsed')
                }
            });
        }
    });
});
var element = new Array();

$(function(){
    lastName = window.location.pathname.split("/");
    currentWindowLocation =  lastName[lastName.length-1];
    var fileLocation = $('a[href="'+currentWindowLocation+'"]');
    $('a[href="'+currentWindowLocation+'"]').parents().map(function(){
        element.push(this);
        }
    ).get()

    $('a[href="'+currentWindowLocation+'"]').attr('href','#');
    var arrayLength = element.length;

    for (var i = 0; i < arrayLength; i++) {
        if(element[i].tagName == "UL" && element[i].className.match(/sub-menu/g) ){
            element[i].setAttribute('style', 'display:block');
        }
        if(element[i].className.match(/has-children/g)){
            element[i].className = "has-children opened";
        }
    }


});

Another issue that arises across all browsers – though it's more of a functionality question than a bug – is when clicking on a parent menu to reveal a sub-menu and then being redirected to the relevant page.

What I want to achieve is - Upon initial click, the sub-menu should not open. Instead, upon redirection to the new page, the sub-menu opens up.

Answer №1

Received a solution from one of my friends offline

They suggested replacing:

element[i].setAttribute('style', 'display:block');

with:

element[i].style.display = "block";

Tried it out and it worked like a charm!

:)

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

Adjusting height in Google Maps to fill the remaining space

Currently, I am developing a map application where I want the Google Maps DIV to occupy the remaining height under the header. Here is the code snippet: <!DOCTYPE html> <head> <title>Map Application</title> <style type ...

Customize Filepond Image Uploader settings on multiple instances

Struggling with customizing Filepond instances, I am looking to set individual setOptions for each Filepond. The challenge lies in figuring out how to make setOptions unique to each instance and not apply universally. Is there a way to configure the plugi ...

Is there a way to transfer a value to a different PHP file using AJAX and JavaScript object?

After trying to json_decode the json.stringify data, it returned NULL. I used **json_last_error to determine the error and received the following error message: Syntax error, malformed JSON I need someone to review my ajax code enclosed within this javas ...

Interacting with the DOM of an iFrame from a separate window using Javascript

My main webpage is hosted on "DomainA" and it contains an iFrame sourced from "DomainB". Within this iFrame, there is a click event that opens a new window, also sourced from "DomainB". I am attempting to update an input field within the iFrame from the n ...

Node.js: Experiencing HTTP request timeout issues lasting for over a minute

Using Node.js (version 0.10.28), I encountered an issue when making an http.request to my Ruby API for a large amount of data. The request seems to time out and return a 404 error after only 1 minute. Interestingly, when using other methods like wget or jQ ...

Mobile responsiveness issue with basic bootstrap navigation bar not collapsing

After trying everything possible, I am still unable to resolve my issue and it is leaving me puzzled. MY ISSUE Simplifying my page, I used the example from w3schools for a responsive navbar. When resizing the browser window, the navbar collapses correctl ...

retrieve the index from the chosen elements

Hey there! I'm facing a situation where I have a div with several child elements. Using jQuery, I want to find the index of a specific element within a certain selector. <div> <div class="red"></div> <div class="red"></ ...

Enable the use of custom tags containing hyphens in the kses filter for WordPress

I developed a specialized Wordpress plugin that enables users to incorporate custom HTML element tags (such as <my-element>) into the content of a Post. This allows users without the unfiltered_html capability to utilize predefined custom tags. The ...

What could be causing the sudden increase in time taken for AJAX requests, going from a mere 2 milliseconds to over 50 milliseconds?

Recently, I developed a script using jQuery for AJAX that allows me to "ping" the server and measure the time it takes for my AJAX requests to complete. var start = Date.now(), end = 0; setInterval(function() { $.ajax('', { complete ...

"Change the value of a style setting in React to 'unset

One of the components has CSS properties such as `right` and `bottom` that are set with a classname. I tried to override these values using the `style` prop but have only been successful in setting numerical values like `10px` or `0px`, not `unset`. Wha ...

Encountered a JQuery error in the application: trying to call the 'open' method on dialog before initialization is complete

I am having trouble integrating a dialog box into my application and encountering the error mentioned above. Here is the jQuery code I'm using: $( "#dialog" ).dialog({ autoOpen: false, width: 450, modal: true, ...

Is it possible to render the v-for value dynamically?

I have a dynamic component and I'm trying to iterate through different objects from it. However, my current code isn't working as intended. Can someone please guide me on how to make the activeQuestion value in v-for dynamic? Thank you for your a ...

Reproducing contents from an HTML div

I am facing a challenge with two <div> elements that share the same structure, but differ in their id and name. My goal is to transfer the values from one div to the other while preserving attributes and copying only the value attributes. This was m ...

Interactive Ionic menu available on a designated page for enhanced user engagement

English is not my first language, so please bear with me. Here's the situation: I have a map section (using leaflet) on one page of my app, along with a menu for displaying data to the user. Currently, the menus are located in my app.component.html b ...

Updating the direction of THREE.DirectionalLight is not possible

It seems that the DirectionalLightShadow is always looking at Vector3(0,0,0). Although I have tried to set a different direction for it below, it still appears to be looking at (0,0,0). The light.shadow.camera continues to face towards the origin. var li ...

Is there a way to change a .pptx document into a base64 string?

Currently, I am working on a project that involves creating an addin for Office. The challenge I am facing is opening other pptx files from within the addin. After some research, I discovered that I need to use base64 for the PowerPoint.createPresentation( ...

"Utilizing the power of Angular 6's JSON pipe

Looking for a well-structured formatted JSON, but all I get is confusion and this strange image: https://i.sstatic.net/6mvBu.png Does anyone have any insights on what might be causing the issue? HTML <span style="font-weight: 500;">Payload Data: ...

What is the best method for sending form data, specifically uploaded images, in Python Bottle with Ajax?

This form belongs to me <form method='post' enctype='multipart/form-data' id='uploadForm' name='formn'> <input type='file' value='' name='newfile'> <input type=&a ...

How can I test for equality with an array item using v-if in Vue.js?

Currently, I am facing a challenge in my Vue.js project where I need to determine if a number is equal to an element within an array. Here is the code snippet that I am working with: <div v-if="someValue != arrayElement"> // </div> I am st ...

Utilize Google API V3 to create a dropdown selection list of locations, extracting latitude and longitude values from a JSON text file

I am working on creating a map using Google Maps API v3. I have implemented a dropdown select list for different places and I am pulling the latitude and longitude values from it. Initially, I manually added the options like this: <option value= ...