javascript - Calling function in custom function from 'outside' -
i've asked question (call function in custom function) find out how call function within custom function , works great. use prepareslide function on onclick in html however. how can call prepareslide within itemslider function?
jquery('.item_holder').itemslider(); $.fn.itemslider = function (details) { var itemholder = this; this.prepareslide = function(slidenumber) { alert(1); } itemholder.prepareslide(1); } the itemslider function adds pagination @ bottom of slider onclick navigate slide right away(that's how should work atleast) so:
<a href="#" class="number" onclick="prepareslide(1);" id="number_1"> </a>
you can't add onclick event, , if could, shouldn't.
the function have written adds prepareslide() functionality jquery, means needs called on jquery object. unable access method outside of jquery.
this thing you, since shouldn't using onclick attributes in html, anyway. jquery's event-handling model more powerful , more flexible, , accessed via like:
$('#number_1').on('click', function () { $('.item_holder').prepareslide(1); }); this 1 of (imho) jquery's useful functionalities, easy access event , document object models. if you're feeling ambitious, can change selector $('.number') , adjust code extract number id field, , cover entire list in 3 or 4 lines of code.
Comments
Post a Comment