0

Hey all-

No doubt, I'm going to be redirected to various threads, but I've looked & I still haven't been able to find the proper solution to my problem.

Scenario: Fairly large site, most data is brought in via ajax...

Sometimes the data brought back might include a dropdown menu or slider that wants to use jQuery...and I simply cannot find a nice simple way to get jQuery to reevaluate the DOM only when it needs to...

I've looked at .live and .on and a bunch of other methods, but -- if I understand correctly -- this approach essentially requires an event listener, which I really don't want to use; if the user loads 100 pages, only a handful of them may contain a jQuery-oriented object...

So, all I really want to do is to load stuff via ajax, and IF there's a JQuery-using object somewhere in the return, I want to tell jQuery to reinitialize itself...but there seems to be no way to do that....

Little help?

Many thnx,

-Midgard

3
Contributors
7
Replies
28
Views
4 Years
Discussion Span
Last Post by paulkd
0

Well, yeah, that's the basic idea, but how do you tell jQuery to reevaluate the dom?

Example:

Page loads, dom is evaluated

1) user clicks on something. ajax calls replace part of page
2) user selects something. ajax updates part of page
3) user clicks on something else. ajax replaces part of page and the code returned includes a jQuery element -- a slider, dropdown menu, slideshow, whatever.

How do you tell jQuery to reevaluate the dom when it needs to (that is, a new element is crated that jQuery needs to know about)?

Hope this explains the situation better!

0

Presumably your code simply returns HTML elements not "jQuery" elements?

Are the returned elements random or known?

0

paulkd-

Presumably your code simply returns HTML elements not "jQuery" elements?

Hmmmm.....not sure what you mean....as an example, one of the returns includes a <ul> list thqat has a class of <ddmenu>. The css & js included on page load format this class as a drop-down menu -- but only if the actual list is also included on page load; if loaded via ajax, the css formats it correctly, but the js (which is actually jQuery calls) does nothing...which is why I'm trying to reinitialize jQuery to reevaluate the page as needed...

Are the returned elements random or known?

Depends on what you mean. When the user clicks a button, it is known whether or not any elements that want to use jQuery will be returned. However, if/when the user clicks on that button is entirely unknown....

Thnx!

-Midgard

0

Can you provide the code relevant to the <ul> and ddmenu (css and js)?

Is there a reason you are fetching an unordered list and converting it into a select rather than simply fetching a select?

0

Is there a reason you are fetching an unordered list and converting it into a select rather than simply fetching a select?

because it uses submenus (arbitrary tree)

This whole thing started when they wanted to use Liquid Slider <Click Here>...wouldn't work after an ajax call, so I cheated and did a full page reload when it came up...

Now they want to use DrillDownMenu <Click Here> & I got the same problem -- works great if included with page load, not at all if loaded via ajax...

With both of these, jQuery is initing itself on page load, and all I want to do is to be able to tell it to reinit itself after an ajax call that loads one of the above plugins...and I'd like to avoid having to do full page reloads, as they'll probably come up with a new jQuery lib to be used...but only in certain circumstances....

Does this help?

Thnx!

0

ok, I mistook your use of "drop-down menu" for a select.

I also, at this point, do not see a need to do page reloads. Do you "control" all of the code and data that is being executed/fetched?

If you are able to attached code (via copy/paste or attachment) that would be useful, if not I will create some Proof Of Concept code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.