Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call function in jquery from javascript

<script type="text/javascript" src="jscripts/jquery.js"></script>

<script type="text/javascript">
$(document).ready(function(){
alert("funciton");
    $(function(){
        $.fn.gotof(){
            alert("I am calling form jquery");
        }           
    });
});
</script>


<input type="button" onclick="dofunc();">

<script type="text/javascript">
    function dofunc(){
        gotof();
    }
</script>

how do i call gotof() that is present in jquery and below is the code written over jsfiddle

like image 814
Rafee Avatar asked Dec 07 '25 03:12

Rafee


1 Answers

There are a few errors in your code. Fixed it should look like this:

$.fn.gotof = function() { // has to be defined as a function, does not need to be inside a nested document ready function
    alert("I am calling form jquery");
};

$(document).ready(function() {
    alert("function is ready to use now");
});

function dofunc() {
    $.fn.gotof();  // can call it using $.fn.gotof(), but it should really be called properly via a selector $('div').gotof();
}

http://jsfiddle.net/pSJL4/8/

like image 157
Richard Dalton Avatar answered Dec 08 '25 23:12

Richard Dalton