0

I'm trying to build a mega menu with the code below.

This is the link from the menu to show the mega menu

<li><a href="javascript:void(0);" id="mmBtn"></li>

And this is the javascript

// Get the modal
var modal = document.getElementById('mmCat');

// Get the button that opens the modal
var btn = document.getElementById("mmBtn");

// Closes the modal
var span = document.getElementsByClassName("close")[0];

// Open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

// Close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// Close it from outside
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

Is it possible to use a link like this instead to get the ID and not reload the page and not showing the hashtag in addressbar?

<a href="test.com/products#mmBtn">
perqedelius
  • 105
  • 1
  • 1
  • 10
  • 1
    Possible duplicate of [Javascript getElement by href?](https://stackoverflow.com/questions/10572735/javascript-getelement-by-href) – Liam Dec 07 '17 at 09:02
  • Yes, that's possible. Here are the steps: **1.** Bind click event on all the anchors having hash in it `a[href*="#"]`. **2.** In handler, extract the hash of the clicked link **3.** Scroll to that element **4.** Prevent redirect. – Tushar Dec 07 '17 at 09:05
  • Oh, that's over my head. But I will give it a try and Google for solutions for all 4 steps. – perqedelius Dec 07 '17 at 09:29

0 Answers0