javascript - Does this function execute : jQuery(".class").function(); if the class is not found on this page? -
Just a quick question.
I am thinking that if the following code contains unslider () if there is no .banner class on the page then run it?
jQuery ("banner"). Unslider ();
I do not want to run it on pages, where nobody is there. Banner class
Do I need to do something
if (jQuery (".banner")> 0) {jQuery ("banner"). Unslider (); }
Yes, it runs and executes the following:
$ .fn.unslider = function (o) {var len = this.length; / Enable multiple slider support (unit) {// copy of cache $ (this), then this is me var = $ (this); Var example = (new unsledder). (Me, o); // An unsuller example for me. Data ('assisted' + (lane> 1? '-' + (index + 1): ''), example);}); };
Then it does .each ()
on your archive.
However, if that collection is empty, then the function will not run BTW, this one .each
and therefore the best description of "not much" will be that if you enter $ ( '. Banner'), what will happen Unslider (); Trying to do this and doing "optimization" will not be the means to do this by examining
.length
, unless you are not sure that the call Be heavy
Comments
Post a Comment