Thursday, April 21, 2011

JQuery event / manipulation not working

This is just a silly mistake I made which I thought I should share with the internetz. When assigning JQuery events to html elements, be sure to do it only after they have been loaded. If you just put them straight into a script file the elements wouldn't have loaded when it executes and hence the event won't work.

Make sure that all html DOM manipulation is done after the html loads by putting the javascript code inside a

$(document).ready(function() {
   event and manipulation stuff here :D

1 comment:

  1. You can leave jQuery out of this and make it more generic since it applies to all DOM manipulation activities:

    window.onload = function () {
    element.onlick = ...