Unable to run JavaScript in app

About Support App Unable to run JavaScript in app

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6482
    Avatar for kcclemokcclemo
    Participant

    Hello,
    I am not able to get my JavaScript to work in the app. It works in my standard browser, but, not the app.

    Is there something special I need to do to get it to execute JavaScript?

    Note, I’m not using JQuery or any third-party plugins. Here is the code I’m attempting to run:
    `
    document.addEventListener(“DOMContentLoaded”, function() {
    var today = new Date().getTime();
    var events = document.querySelectorAll(‘.event’);

    events.forEach(function(event) {
    var expires = new Date(event.getAttribute(‘data-expires’)).getTime();

    if (today < expires) {
    event.classList.remove(‘hidden’);
    }
    });
    });
    `

    I’ve attempted both in-lining the JavaScript and referencing it as an external file but, neither works. Is there a way to debug the console errors I may be encountering?

    #6487
    Avatar for Andy MoyleAndy Moyle
    Keymaster

    You can use jQuery – I can read that better šŸ˜‰
    It’s likely to be todo with the DOMContentLoaded having already fired by the time your code is rendered
    https://stackoverflow.com/questions/39993676/code-inside-domcontentloaded-event-not-working

    #6488
    Avatar for kcclemokcclemo
    Participant

    Ah… OK, that’s a good thought. I’ll give it a try. Thanks!

    #6490
    Avatar for kcclemokcclemo
    Participant

    That worked! Thanks again!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.