I am trying to call a user defined function in jQuery:
$(document).ready(function() {
$('#btnSun').click(function() {
myFunction();
});
$.fn.myFunction = function() {
alert('hi');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnSun">Say hello!</button>
I tried the following as well:
$(document).ready(function() {
$('#btnSun').click(function() {
myFunction();
});
});
function myFunction() {
alert('hi');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnSun">Say hello!</button>
It doesn't seem to work! Any idea where I am wrong?
$('your_html_tag').myFunction()
. jsfiddle.net/H7z8f – Piscine