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
Post a Comment