View Full Version : jQuery Load Re-evaluation

11-08-2010, 06:36 AM
Hi there,

I've recently started a personal project to recreate a flash website using jquery and some jQuery plugins. All has gone well apart from one thing, I've only found one proposed solution to it and I can't seem to get it work since it's not in the context of jQuery.

Here's a description of what I've got so far:

I have a content management system that outputs data to a content div that can contain links, images etc. I have links around this content area that are not inside it that have a class named "ajax-link". This is the same for all of the links inside the content area. Now using the following code, I can get all links that are written by php at load time, to change the content of my content div. (This includes the initial content of the content div)

strTargetPage = $(this).attr("href")+' #content';
$("#ajax").html('<div id="content"><span class="loading-message">Loading, Please Wait.</span></div>')
.load(strTargetPage, function() { return false; });
return false;

This will load the content div of a links target page into the page I'm currently using. This works 100% for any links that are written by php initially. So I'm guessing that anything with a class of "ajax-link" will have this function assigned to it at jQuery's "ready" time.

Is there anyway I can have the newly loaded content be re-evaluated so that the new "ajax-link" links will have this function assigned to them?

I've been told to use javascript's eval() function when I've used standard javascript in the past, but I wouldn't have a slightest clue on how to achieve this in jQuery, as jQuery's load function should be evaluating javascript when it's loaded.

Any ideas/suggestions?
If you need to see my php-generated source code, I can provide it.

Thank you in advance.

11-08-2010, 07:50 AM
Do you mean you are creating new .ajax-link elements via ajax, and you want the same click event applied to them? If so, .live() should do what you want, so your code becomes:


11-08-2010, 07:58 AM
Hey thanks for that.

Yes it's exactly what I've been after. I just read about hijax and similar techniques so I've been looking for a way to do that. A few minutes ago I found the original plugin "livequery" and installed that. I've got it working, but If I can throw out the extra 5kb and replace it with the live() function you mentioned, then it'll be another improvement.