Add an event listener to an object that is added to the DOM via AJAX -


I have a set of checkboxes that have been added to a document via an AJAX call

< Pre> & lt; Input type = 'checkbox' checked class = 'import' & gt; & Lt; Input type = 'checkbox' checked class = 'import' & gt; & Lt; Input type = 'checkbox' checked class = 'import' & gt; & Lt; Input type = 'checkbox' checked class = 'import' & gt; & Lt; Input type = 'checkbox' checked class = 'import' & gt;

I have got some pieces of javascript (using prototype)

  function check-toggle (obj, e) {if (e.shiftKey ) {Obj. Checked =! Obj.checked;} and if (E. Lateke) {obj.checked = true;} and if (e.ctrlKey) {obj.checked = false;}} $$ ('import'). Each (function (obj) {event.obbs (obj, "mouseover", function (e) {warning ('here');}. Bind (this))});  

Now if the checkboxes are on page load on page, the mouseover moves very well.

Unfortunately, if I try and call the "$$" method in some way the checkboxes have been added through AJAX through DOM, none of them take their event listener Does not manage.

So ... anyone knows how to force the prototype to read the current state of DOM? (Or maybe you might think of any other workaround)

I have tried to put $ $ in the function and called it as part of the Exxnet Callback, because one after the AJAX call Output the full $$ function as part of the separate function and actual AJAX values. Not all to make any profit

Help is highly appreciated.

Really was ridiculous.

  function ajax_load_keyset (obj) {url = '/ myurl.html'; Parameters = 'id =' + obj.value; New Ajax.Updater ('checks_go_here', url, {method: 'post', parameters: parameters, empty: true, // this row should be present on success: function (result) {}}); }  

I have found that I need to add evalScripts: true to an AJAX call, then put the $ $ function on /myurl.html page at the end of everything.


Comments