0

I have a heavily customized questionnaire with a list that is looking like that

<ul>  
    <li class="customCheckbox">
    <li class="customCheckbox">
</ul>

This questionnaire is loaded by a JQuery.ajax call and the js code that comes with it is correctly processed when displayed in a JQuery UI dialog. The customCheckbox present on the initial page are correctly processed by my (function($){ [...] }) in an external script jquery.customCheckbox.js

I need something like .live() but since it is removed from JQuery I can't go far with that. I don't want to reload the script in the AJAX call if possible. This question is about the same but me it is not only about an event listener. It modifies the checkbox adding a class and listeners and other stuff.

Actually I am looking for something that would call my (function($)... like $(document).ready.

Thanks

Community
  • 1
  • 1
Johnride
  • 8,476
  • 5
  • 29
  • 39

2 Answers2

1

You can use jQuery.on(), it has replaced .live()

johnkoht
  • 602
  • 6
  • 11
  • I can't use .on since it is not simply an event listener. Actually it is more of a JQuery extension written by one of my partners. I know that .on would handle the events on dynamically created elements. – Johnride Mar 26 '13 at 15:40
  • Johnride - from the jQuery docs description "Attach an event handler function for one or more events to the selected elements." – johnkoht Mar 26 '13 at 15:44
  • I know about `.on` I NEED to reprocess JQuery since it IS NOT only an event listener. – Johnride Mar 26 '13 at 15:47
  • Why don't you just wrap all of your jQuery that you want bound in a function and call it after the ajax is loaded? – johnkoht Mar 26 '13 at 15:55
  • This is very close to what I need but I can't wrap it in a function since I can't edit the code. And I am pretty sure there is a way to call expressely all JQuery functions to run on the loading of a new element. I have seen `evalScripts : true` or something alike with another lib while searching. – Johnride Mar 26 '13 at 16:36
  • Well thinking about it I can take the whole jQuery function and put it in a function processCheckboxes and call it from the jQuery function. I try that. – Johnride Mar 26 '13 at 16:39
0

Don't see the code here you are trying to modify or it is not clear what you are trying to accomplish. Based on what you said, have you tried using .delegate()?

$('#yourButtonIDContainer').delegate('#yourButtonID', 'click', functionCalled);

function functionCalled(e) { e.preventDefault(); *** Do Something Here **** }

Not sure if this helps, but let me know more details if not.

Sharlike
  • 1,789
  • 2
  • 19
  • 30
Matto
  • 236
  • 3
  • 12