Skip to content Skip to sidebar Skip to footer

Jquery: Best Place To Put Html Tag Handlers

Where do you personally prefer to put html tag handlers with JQuery-powered Html page and why: html tag element or document.ready function ?

Solution 1:

Solution 2:

Solution 3:

Solution 4:

for best practice's sake, in .js external files containing functions

functionhandleClick()
{
  $(element).click(function(e){});
}

// then call them on DOM ready with $(function(){}), this is an alternative provided by jquery equivalent to $(document).ready()

$(function(){ handleClick(); });

I do this to have a nice orderly list of functions that is easier to manage. One file, each with a couple of functions to handle the events.

So why not inline? Harder to manage, obstrusive and easier to hack (by easier to hack I mean not that much of a hassle or inconvenience to hack as I can readily modify the DOM with Firebug) compared to a compressed external JS file.

Post a Comment for "Jquery: Best Place To Put Html Tag Handlers"