Add the div's ID to the url after click and then remove it from the url after click close btn
P粉676821490
P粉676821490 2024-04-01 11:46:38
0
2
346

I've done the part of adding the div's ID to the url, but after clicking the class speakers--overlay-close in this speaker--card I can't delete the button after I close it.

var myDivs = document.getElementsByClassName('speakers--card');
    var closeDiv = document.getElementsByClassName('speakers--overlay-close');

    for(var i = 0; i < myDivs.length; i++) {
        myDivs[i].addEventListener('click', function (event) {
          console.log(this.getAttribute("id"));
          let thisID = this.getAttribute("id");
          window.location.href = window.location.href + "#" + thisID;
        });
    }

I've tested some split functions etc but it doesn't work and the url remains the same - using #id.

P粉676821490
P粉676821490

reply all(2)
P粉184747536

I ended up doing something like this, but not sure if this is the right approach:

var myDivs = document.getElementsByClassName('speakers--card');
var closeDivs = document.getElementsByClassName('speakers--overlay-close');

for(var i = 0; i 
P粉376738875

Since the close button is inside the div, when you click it, the event propagates and runs the div's click event handler, which again adds the hash. You can stop event propagation by calling event.stopPropagation() in the close button event handler and then remove the hash from the url.

var myDivs = document.getElementsByClassName('speakers--card');
var closeDiv = document.getElementsByClassName('speakers--overlay-close');

for (var i = 0; i 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!