I'm trying to write my own function like with no luck. "...is not a function"
jQuery.fn.extend ({
myFirstFunction : function () { alert ("first function") }
});
<script type="text/javascript">
$(function(){
$.myFirstFunction();
});
</script>
$.myFirstFunction = function () { alert ("first function") };
<script type="text/javascript">
$(function(){
$.myFirstFunction();
});
</script>
http://jsfiddle.net/Mdqw6/
Or
jQuery.fn.extend ({
myFirstFunction : function () { alert ("first function") }
});
<script type="text/javascript">
$(function(){
$(element).myFirstFunction();
});
</script>
Read more at http://docs.jquery.com/Plugins/Authoring
There is a difference between $.extend() and $.fn.extend(), depending on what you want to do and how you want to access your function:
$.fn.extend({
myFunction: function(){...}
});
$('div').myFunction();
$.extend({
myFunction2: function(){...}
});
$.myFunction2();
In your case, use $.extend() and it should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With