jQuery – Also experienced devs can make newbie mistakes

Today is a lazy Sunday, so I will be quick. It happened to me. Newbie or not, for sure Saturday has its own way to throw it back to you. jQuery. Me lazy, zipping my coffee. Bad combination.

The code:

onLoad="$('#item_id').trigger('click');"

Nothing works. Why? My mind was lacking more coffee. Go and make some more.

Got coffee, inhaled it. Still no clue. Should work, right? No, it doesn’t! Leave aside IE, try Firefox! Suddenly, it works!

The solution is to move the code AFTER the jQuery was loaded, in a specific file or a script tag on the same page! Don’t forget, AFTER jQuery library was loaded! Otherwise, $ selector will not be available.

$(function() {
       $('#item_id').trigger('click');
});

Conclusion: there’s no life before coffee!

Conclusion 2: better more coffee than less!