views:

52

answers:

3

Hi all,

I'm creating an inbox system for my website which allows basic communication between users. I'm fetching the results with jquery calling a webservice.

Then I'm using a jquery template engine to render the results to the screen. So far this all works good. but now I want to add some click functions on certain parts of inbox messages. For example I want the title of the message to be clickable so it will expand/collapse the fulltext which is hidden in a div beneath it.

But I can't seem to use the jquery selectors on this dynamic json result. It works when I put the function in the href tag itself but I don't really want to. I also tried adding the function after the success function but no luck either. Is it possible at all to use selectors with a template engine?

I hope I made myself clear otherwise feel free to ask more information. Thank you very much Kind regards, Mark

+3  A: 

Have you tried jquery .live option? http://api.jquery.com/live/

FutureKode
The .live method only supports a subset of actions but click is one of them. The whole purpose of live is to attach listeners on dynamically added DOM elements.
Erik Noren
A: 

Are you trying to select the json that is returned from the webservice or are you trying to use the jquery selector to find an element that you added previously on to the page?

Amir Raminfar
+1  A: 

Hi guys,

I'm sorry, you'll see it happens all the time, when something goes wrong and I ask a question the minute after it it solves itselves. It is indeed possible to use the jquery selector on dynamic elements. Just make sure u put it after the template processing and in the ajax success function.

Thanks.

Mark