Lets say I may (but also may not) have an element with class order in my DOM.
It maybe create on page load but also, after successful ajax request. My question is, how can I add some live event, that will append something to my element based on it class?
Flow would be like this:
1.Opening page, jQuery searchs for elements with class order, if found, appends something to them (for this question lets say its text "text string"
2.I do an ajax request
3.After ajax request jQuery searchs again for class order and append if found
There is one condition, I DON’T want to trigger any function searching for elements after ajax request, I’d prefere some magic trick with .live() function, if it is possible of course.
EDIT Exact problem
What I was really trying to achive, is appending an img to certain class within newly loaded DOM.
From the beginning:
-
I tried to implementing sortable/paginable table with displaytag and ajax.
-
Then adding (also Ajax) search list filtering.
-
After table is reloaded with Ajax, append images (up or down icon depending on sorting type)
See my answer for results
Firstly, to implement ajax sorting / pagination I used Jquery DisplayTag Ajax pluging, using it is simple, just surround piece of code with
divand run displayTagAjax() function on it.But then, I also wanted Ajaxable table filtering, that was tricky. First step was to create a separate
jsppage with only display tag in it:Table.jsp
Then including this page in MainPage:
Main.jsp
After this steps, we need to fill up our table, so we need a Controller which will change our jsp page to plain html (with static, not ajaxable links yet):
MyController
I dont know if it is good piece of code I wrote, but you’ll get an idea, basically I’m making select from DB based on the values passed by
select, -1 stands for no selected. Next step was to implement proper function injsfile, which will make Ajax GET from my server:Then I had to change displayTagAjax function, I append the url which is equal to Controller mapping URI, so we will always get filtered list when sorting/chaning page:
Finally I appended my images to newly created elements in ajax call, also in this plugin 🙂 :
And thats it, full Ajaxable display tag table, with dynamic filtering results and fancy icons for ordering 🙂