Attempting to remove an attribute or property in JavaScript will not yield the desired result

When I try to close the menu after opening it, the inline style won't get removed despite trying different methods. The CSS only has text properties for alignment and the class can-transform contains a media query.

That's all the information I have at the moment, hope it's sufficient.

// Responsive Header 
(function(window, document) {
  let menu = document.getElementById('menu'),
    rollback,
    WINDOW_CHANGE_EVENT = ('onorientationchange' in window) ? 'orientationchange' : 'resize';

  function toggleHorizontal() {
    menu.classList.remove('closing');
    [].forEach.call(
      document.getElementById('menu').querySelectorAll('.can-transform'),
      function(el) {
        el.classList.toggle('pure-menu-horizontal');
      }
    );
  };

  function toggleMenu() {
    // set timeout so that the panel has a chance to roll up
    // before the menu switches states
    if (menu.classList.contains('open')) {
      menu.classList.add('closing');
      document.getElementById('tutu').removeProperty('display');
      document.getElementById('tututu').removeProperty('display');
      console.log('ZOINK')
      rollBack = setTimeout(toggleHorizontal, 500);
    } else {
      if (menu.classList.contains('closing')) {
        clearTimeout(rollBack);
      } else {
        toggleHorizontal();

      }
    }
    menu.classList.toggle('open');
    document.getElementById('toggle').classList.toggle('x');
    document.getElementById('tutu').style.display = 'block';
    document.getElementById('tututu').style.display = 'block';
  };

  function closeMenu() {
    if (menu.classList.contains('open')) {
      toggleMenu();
    }
  }

  document.getElementById('toggle').addEventListener('click', function(e) {
    toggleMenu();
    e.preventDefault();
  });


  window.addEventListener(WINDOW_CHANGE_EVENT, closeMenu);
})(this, this.document);
.can-transform {
  display: none;
}
<div class="pure-g main-menu" id="menu">
  <div class="pure-u-1 pure-u-sm-1 pure-u-md-1-4 pure-u-lg-1-4">
    <div class="pure-menu-heading">
      <a href="/" class="pure-menu-heading">
        <img class="hdr-logo" src="/layout/local/public/img/new_logo.gif">
      </a>
      <a href="#" class="hamburger" id="toggle"><s class="bar"></s><s class="bar"></s><s class="bar"></s></a>
    </div>
  </div>
  <div class="pure-u-1 pure-u-sm-1-4 pure-u-md-1-3 pure-u-lg-1-4">
    <div class="pure-menu-horizontal can-transform" id="tutu">
      <ul class="pure-menu-list">
        <li class="pure-menu-item"><a href="/project/upload" class="pure-menu-link">Create Project</a></li>
        <li class="pure-menu-item"><a href="/projects" class="pure-menu-link">Your Projects</a></li>
        <li class="pure-menu-item"><a href="/help" class="pure-menu-link">Technical Help</a></li>
      </ul>
    </div>
  </div>
  <div class="pure-u-1 pure-u-sm-1-4 pure-u-md-1-3 pure-u-lg-1-3 main-menu-right">
    <div class="pure-menu-horizontal can-transform" id="tututu">
      <ul class="pure-menu-list">
        <li title="Client Area" class="pure-menu-item">
          <a href="/account" class="pure-menu-link">
            <svg class="svg-inline--fa fa-user fa-w-14" aria-hidden="true" focusable="false" data-prefix="far" data-icon="user" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M313.6 304c-28.7 0-42.5 16-89.6 16-47.1 0-60.8-16-89.6-16C60.2 304 0 364.2 0 438.4V464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48v-25.6c0-74.2-60.2-134.4-134.4-134.4zM400 464H48v-25.6c0-47.6 38.8-86.4 86.4-86.4 14.6 0 38.3 16 89.6 16 51.7 0 74.9-16 89.6-16 47.6 0 86.4 38.8 86.4 86.4V464zM224 288c79.5 0 144-64.5 144-144S303.5 0 224 0 80 64.5 80 144s64.5 144 144 144zm0-240c52.9 0 96 43.1 96 96s-43.1 96-96 96-96-43.1-96-96 43.1-96 96-96z"></path></svg>
            <!-- <i class="far fa-user"></i> Font Awesome fontawesome.com -->
          </a>
        </li>
        <li class="pure-menu-item">
          <a title="Logout" href="/logout" class="pure-menu-link">
            <svg class="svg-inline--fa fa-sign-out-alt fa-w-16" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="sign-out-alt" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M497 273L329 441c-15 15-41 4.5-41-17v-96H152c-13.3 0-24-10.7-24-24v-96c0-13.3 10.7-24 24-24h136V88c0-21.4 25.9-32 41-17l168 168c9.3 9.4 9.3 24.6 0 34zM192 436v-40c0-6.6-5.4-12-12-12H96c-17.7 0-32-14.3-32-32V160c0-17.7 14.3-32 32-32h84c6.6 0 12-5.4 12-12V76c0-6.6-5.4-12-12-12H96c-53 0-96 43-96 96v192c0 53 43 96 96 96h84c6.6 0 12-5.4 12-12z"></path></svg>
            <!-- <i class="fas fa-sign-out-alt"></i> Font Awesome fontawesome.com -->
          </a>
        </li>
      </ul>
    </div>
  </div>
</div>

Answer №1

After some trial and error, I finally cracked the code! All it took was placing it in the correct function.

// Custom Responsive Header Function 
(function (window, document) {
    let menu = document.getElementById('menu'),
        rollback,
        WINDOW_CHANGE_EVENT = ('onorientationchange' in window) ? 'orientationchange' : 'resize';

    function toggleHorizontal() {
        menu.classList.remove('closing');
        [].forEach.call(
            document.getElementById('menu').querySelectorAll('.can-transform'),
            function (el) {
                el.classList.toggle('pure-menu-horizontal');
                document.getElementById('tututu').style.display = '';
                document.getElementById('tutu').style.display = 'none';
            }
        );
    };

    function toggleMenu() {
        // Adding a timeout to ensure the panel rolls up smoothly before changing menu states
        if (menu.classList.contains('open')) {
            menu.classList.add('closing');
            console.log('ZOINK')
            rollBack = setTimeout(toggleHorizontal, 500);
        } else {
            if (menu.classList.contains('closing')) {
                clearTimeout(rollBack);
            } else {
                toggleHorizontal();

            }
        }
        menu.classList.toggle('open');
        document.getElementById('toggle').classList.toggle('x');
        document.getElementById('tutu').style.display = 'block';
        document.getElementById('tututu').style.display = 'block';
    };

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

My ng-view html is unexpectedly displaying as plain string. What steps should I take to resolve this issue?

Why is my ng-view HTML displaying as plain text? How can I resolve this issue? I have encountered an error, here is the screenshot for reference: Unfortunately, I am unable to upload images at the moment. ...

Connecting a href link to a TAB

Check out this useful CODE example I am using. I have a webpage with links that have href attributes. Now, I want to link these pages to another page and have them automatically open a specific tab when clicked. Is this possible? Here are the links on th ...

Using jQuery's append function will retrieve external source files within script tags, however, it will not officially render them in the DOM

After including a script with an external source and attempting to parse it using jQuery, the script is downloaded but not loaded into the DOM. This issue persists regardless of which jQuery DOM insertion method I use, such as .append(). Take a look at th ...

Creating a Delicious Earth Progress Pie

I'm looking to incorporate a unique progress bar design on my website, similar to this one: The progress pie Can anyone guide me on how to create a progress pie with an image inside it that changes color as it moves? ...

What is the best way to implement a Navbar link in React.js?

I am currently working on developing a website using Reactjs. I have successfully created a Navbar with two links - Home and Contact. However, when I click on the Contact link, although the URL changes accordingly, the page itself does not update. I have s ...

Trigger is not activated by dynamically created element

I am dealing with a block of code that is dynamic and looks like this. var li3 = document.createElement('li'); li3.classList.add("col-sm-3"); li3.classList.add("no_padding"); var inner = ""; inner = inner ...

Sending Ajax data to a controller function

I am looking for guidance on how to pass values from my view to my controller using ajax. As someone who is new to working with ajax, I would appreciate some assistance in understanding the process. Full Page @model ALSummary.Models.MonthReport @{ ...

How can I use JavaScript or JQuery to retrieve the HTML content as a string from a specific URL?

How can I extract the URL of a link from a webpage and add it to my code without an ID for that specific link? Is there a way to search based on the content within the <a> tag? ...

The linking process in AngularJS is encountering difficulties when trying to interact with

I've already looked at similar questions, and my code seems correct based on the answers provided. It's a very simple beginner code. <html ng-app=""> <head> <title>Assignment</title> <script src=" ...

Angular - send multiple HTTP requests for the length of an array and combine the responses into one array

Exploring angular for the first time and dabbling with the trello API. I have an array containing some list IDs that I need to make HTTP GET calls for, equal to the length of the array. For instance, if there are two IDs in the array, then the HTTP call sh ...

Is there a way to efficiently update specific child components when receiving data from websockets, without having to update each child individually?

Currently, my frontend requires updated data every 2 seconds. The process involves the frontend sending an init message to the backend over a websocket. Upon receiving this message, the backend initiates an interval to send the required data every 2 second ...

Is it better to parse HTML in PHP or JavaScript for an iPhone web application?

I am in the process of creating a web application for iPhone/iPod touch. I need to incorporate an external HTML file and extract specific data from it. One approach is to handle this on the server side by creating a separate page that echoes the desired d ...

What is the default method for automatically disabling drop down fields?

I've created a script that will gray out a drop-down field if a prior selection wasn't made. Once the appropriate choice is selected, the grayed-out field will become active. My query is, how can I set the drop-down field to be initially grayed ...

Utilize separate production environments for each client on the NodeJS server to ensure seamless operation and

After conducting extensive research, I have been unable to find a solution to my current problem. I am operating a Node server with multiple environments (dev, test, demo, prod). The server is deployed on a Linux server in the production environment via a ...

Tips for retrieving information from a dynamically created form using VUE?

Welcome Community I am working on a parent component that includes a child component. The child component dynamically renders a form with various controls from a JSON object retrieved via a Get request using Axios. My goal is to be able to read and loop ...

Bringing in the node-spotify or spotify-web modules to the browser for seamless integration

Has anyone successfully used Spotify's Playlist API in a browser? It seems that the web API only covers metadata, and to access the full API I need to use libspotify. Do I need to set up a Spotify API server myself or use node libraries like node-spot ...

Tips for initiating a browser file download using JavaScript, ensuring that the download is only carried out if the web service responds with

For a project I am working on, I need to create JavaScript code that will be triggered by clicking on an <a> element. This code will then make a GET request to a web service that I am currently in the process of coding. Once the service returns a fil ...

The overflow:hidden feature doesn't appear to be functioning as expected

I am struggling to hide the text details within a div containing text and image, organized in ul li structure. Despite applying overflow hidden to the .sbox class, the text details refuse to remain hidden and appear to be overflowing. Explore this issue o ...

When you try to remove an element from an array by its index in Vue JS, the outcome may not be

Here is an array that I have: var hdr = ("name", "date", "start_time", "selling_item", "total_call", "end_time", "ad_num", "area", "order_num"); //this data comes from the database Now, I need to rename these array elements according to prope ...

The Safari 7.1+ browser seems to be having trouble with the spotlight effect

Why is the CodePen not functioning properly in Safari? Despite working well in Chrome and Firefox, it completely fails to work in Safari 7.1+. Can anyone provide some insights? http://codepen.io/cchambers/pen/Dyldj $(document).on("mousemove", function( ...