jquery - AJAX based page needs repetitive javascript actions -


i'm working on application uses jquery layouts , loads website parts (like gmail). every time load "panel" using jquery have substitute links make work panels (i.e., load link content in panel, not in full page). this:

function changemainpane(href) {     $("#screen").load(href);     $("#screen a.ajax-page").click(function () {return         changemainpane($(this).attr("href"))     }); } 

this simplified changemainpane function, mine has tens of $("#screen ...").click() calls integrate new piece of html page.

the question is: there better way this? like:

$("#screen").ready(function() {     // html setups } 

or "always user clicks on link, check if has ajax-page class , call function" without having initialize each link independently.

you can have @ delegate method. delegate method can registered common parent element of links on wants reload main panel. can document object or lower level element "body" or div "div.mylinks".

$(document).delegate("a.ajax-page", "click", function(){     changemainpane($(this).attr("href")) }) 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -