php - How to gather a jQuery object into the .on event using parameters rather than being in the global scope? -
that tricky question phrase. elaborate.
i have object datatable in case, jquery object.
i listen button click .on click event , call function called checkbox parameter of object:
var temporaryfilestable; $(document).ready(function() { temporaryfilestable = $("#temporaryfilestable").datatable(); $("#checkboxbutton").on('click', function() { checkbox(temporaryfilestable); }); });
this works fine , temporaryfilestable passes object function checkbox.
the object "temporaryfilestable" reference datatable - both called within document ready of ajax triggered php / js file.
in .js file store of reusable functions have function checkbox(checkboxtable).
this function creates modal has several buttons on. want use these buttons call functions such selectfiltered(checkboxtable).
because function checkbox(temporaryfilestable) brings in table object need reuse object trigger next function. used passing variables parameters functions using onclick="function(parameter)", or in case modal have use:
function checkbox(checkboxtable) { ... var content = '<a href="#" onclick="selectfiltered('+checkboxtable+') class="button>' ... <!-- trigger modal --> }
this doesn't seem work anyway syntax wrong not point. reluctant use onclick correcting code use jquery .on click instead.
without declaring temporaryfilestable global object can somehow jquery object .on click listener?
if not, suppose consider declaring datatable object global can accessed across multiple .js files, rather passing around functions much? problem means have write functions trigger jquery on each datatable object, might not in dom @ time. guess that's not ideal.
** additional info ** code check checkboxes in way wanted worked fine before started passing table parameter. wanted because have multiple pages, different tables, use same checkbox ticking modal , functions. can post original code if helps didn't want confuse question.
to clarify realise declare temporaryfilestable putting global scope in first section of code don't think passes between .js files. allow me use outside of document ready.
thanks reading.
i suggest trying attach on click event after html append dom. object doesn't play nice when passed string through function. try this:
$("#appedto").append(content); //then select a, , attach on click event $([selector link]).on("click", function(){ selectfiltered(checkboxtable); });
Comments
Post a Comment