small jquery extension doesnt work -
after trying several ways of (first time) creating extension jquery... , doesn't work yet:
(function($){ $.fn.fixinputwidthsforblog = function() { console.log('hi extension'); // var w = $('#newblogentryform input[name="headline"]').outerwidth(); // $('#newblogentryform textarea[name="text"]').outerwidth(w); // $('#newblogentryform submit[name="submit"]').outerwidth(w); }; // endfunc }(jquery));
this (following) error:
"jquery-3.1.0.min.js:2 uncaught typeerror: $.fixinputwidthsforblog not function"
$(document).ready(function(){ $.fixinputwidthsforblog(); alert('ok1'); $(window).on('resize', function(){ $.fixinputwidthsforblog(); }); $('.linknewblogentry').on('click',function() { $('#newblogentryformdiv').slidetoggle().delay(1200).fixinputwidthsforblog(); // settimeout("fixinputwidthsforblog();",1200); return false; }); });
i tried:
$.fn.extend({ fixinputwidthsforblog = function() {} });
and simply:
$.fn.fixinputwidthsforblog = function() {};
but of them result in same error:
"jquery-3.1.0.min.js:2 uncaught typeerror: $.fixinputwidthsforblog not function"
in line try execute:
$.fixinputwidthsforblog();
in 1 way or another.
extending $.fn
works element chains, not own function of jquery object. need extend $
directly, without fn
.
(function($) { // jquery plugin $.fn.onelements = function() { console.log('hi, element chain plugin'); // make chainable return this; }; // jquery object extension $.onjquery = function() { console.log('hi, jquery object extension'); }; }(jquery)); // work $('someelementselector').onelements(); $('someelementselector').onelements().onelements(); $.onjquery(); // not work // $('someelementselector').onjquery(); // $.onelements();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment