+ 1

Calling jQuery function from "normal" JavaScript

Hello everyone, could you anyone help me with my rpblem please? I would like to call jquery function from JS (and additionally pass JS variables to jQuery). Here is my sample code: <script> $(document).ready(function() { function print(num) { alert(num); } }); var something = 10; print(something); </script> Thanks a lot for help :)

15th Nov 2017, 4:43 PM
Radek Horáček
Radek Horáček - avatar
6 Respostas
+ 1
If your question is simply if you can mix jQuery and JavaScript together, then yes you can.
15th Nov 2017, 5:29 PM
AgentSmith
+ 3
What problem are you running in to? Btw, throw your var/print stuff at the bottom inside of the .ready(). If not, it'll try to run the function before you even defined the function. $(function() { function printIt(num) { alert(num); } var something = 10; printIt(something); }); https://code.sololearn.com/WSFxQ6nk39Eq/#js
15th Nov 2017, 4:57 PM
AgentSmith
+ 1
Hello, thanks for fast reply. In my real website, I have a html5 video player with JS function (onended action in video tag). This function plays another video by changing video src and I also need this function to run jQuery to run php file command. Would it work like this? Thanks for reply Radek :)
15th Nov 2017, 4:59 PM
Radek Horáček
Radek Horáček - avatar
+ 1
Should I post my real code here, so you can better understand? My explanation may be a bit confusing, English isn't my first language.
15th Nov 2017, 5:03 PM
Radek Horáček
Radek Horáček - avatar
+ 1
$ function
8th May 2021, 10:17 AM
IMTIAZ AHMAD
IMTIAZ AHMAD - avatar
+ 1
$ function
15th Nov 2022, 10:39 PM
Ahmed Khaled Sobhi
Ahmed Khaled Sobhi - avatar