• Resolved WebDragon

    (@webdragon)


    Your codeblock here, has a slight bug

    // from https://stackoverflow.com/a/70062967/5317678
    // open closed details elements for printing
    window.addEventListener('beforeprint',() =>
    {
        const allDetails = document.body.querySelectorAll('details');
        for(let i=0; i<allDetails.length; i++) { if(allDetails[i].open) { allDetails[i].dataset.open = '1'; } else { allDetails[i].setAttribute('open', ''); } } }); // after printing close details elements not opened before window.addEventListener('afterprint',() =>
    {
        const allDetails = document.body.querySelectorAll('details');
        for(let i=0; i<allDetails.length; i++)
        {
            if(allDetails[i].dataset.open)
            {
                allDetails[i].dataset.open = '';
            }
            else
            {
                allDetails[i].removeAttribute('open');
            }
        }
    });

    It should look like

    window.addEventListener('beforeprint',() =>
    {
        const allDetails = document.body.querySelectorAll('details');
        for(let i=0; i<allDetails.length; i++) {
            if(allDetails[i].open) {
                allDetails[i].dataset.open = '1'; 
            } else {
                allDetails[i].setAttribute('open', '');
            } 
        } 
    }); // after printing close details elements not opened before 
    window.addEventListener('afterprint',() =>
    {
        const allDetails = document.body.querySelectorAll('details');
        for(let i=0; i<allDetails.length; i++)
        {
            if(allDetails[i].dataset.open)
            {
                allDetails[i].dataset.open = '';
            }
            else
            {
                allDetails[i].removeAttribute('open');
            }
        }
    });

    In the process of smashing the first window.addEventListener into one line, you inadvertently included the *second* window.addEventListener into the comment preceding it

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter WebDragon

    (@webdragon)

    argh nevermind – it wasn’t your optimizer – some bozo edited the page with the wrong wordpress editor and munged the code

    Plugin Support Plamen M

    (@plamenm)

    Hello, @webdragon,

    Thank you for the update. I am glad that you found a solution.

    Regards,
    Plamen.M
    Tech Support Team
    SiteGround.com

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bug in Javascript with your ‘details elements’ helper’ is closed to new replies.