How can I call a jQuery function from JavaScript?
//jQuery
$(function() {
function my_func(){
/.. some operations ../
}
});
//JavaScript
function js_func () {
my_func(); //== call JQuery function
}
How can I call a jQuery function from JavaScript?
//jQuery
$(function() {
function my_func(){
/.. some operations ../
}
});
//JavaScript
function js_func () {
my_func(); //== call JQuery function
}
Not sure y do you need this anyway here's a simple example...
$(function(){
$('#my_button').click(function(){
alert("buttonClicked"); //Jquery
});
});
function my_func(){
$('#my_button').click(); //JavaScript
}
//HTML
<button id="my_button" onclick="my_func();"></button>
Extend your function to jquery, then use it with $
$.extend({
my_jsFunc: function() {
console.log('============ Hello ============');
}
});
$(function(){
$.my_jsFunc();
});
you are asking the wrong question but I think what you are searching for is:
$.my_func();
the my_func() is just normal function so should be kept outside jquery Dom ready function
$(function() {
my_func();
});
// This function should be outside from jquery function
function my_func(){
/.. some operations ../
}
$(function() {
function my_func(){
/.. some operations ../
}
})
runs the everything inside when the page is "ready".
You don't need that.
Just define the function list this
function my_func(){
/.. some operations ../
}
P.S. "How can i call a jQuery function from JavaScript?" is a bad question. jQuery is a library written using Javascript.
You can do it by actually changing the declaration to outside jQuery callback, but if you have some specific purpose following will work for you
$(function() {
window.my_func = function() {
/.. some operations ../
}
});
//JavaScript
function js_func () {
my_func(); //== call JQuery function
}