Bug in Javascript with your ‘details elements’ helper

[ad_1]

Your codeblock here, has a slight bug

// from 
// 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

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer