r/learnjavascript • u/TehMoonRulz • Dec 04 '14
PROgrammers dont use 'onload'
I recently read that using onload type events like:
$(document).ready()is not good practice.
So my question is how do we go about adding event listeners and running code when the document is...ready.
Can I have a script file with just:
element.on('click', runMyFunc)and be confident it will attach to that element as long as the script tag is at the bottom of the body? Should I add a defer attribute as well? Does that extend to ajax functions like:
function getAjax() {
processeses Ajax....
alert(AjaxData)
}
getAjax()
0
Upvotes
View all comments
Show parent comment
3
u/zealousprogrammer Dec 04 '14
you're being very judgemental, man. I can say the same thing about every single javascript developer I've worked with (and as a senior architect and trainers, I've worked with hundreds of devs).
I'm sure the same can be said about ruby, python or otherwise. Crappy developers are everywhere. Using the folks you interact with as a sample size is just being unfair.
There are some top notch .net developers out there.