Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    81
    Thanks
    1
    Thanked 0 Times in 0 Posts

    putting jQuery in JavaScript

    I'm sorry this must be a really stupid question but I don't understand anything of it.

    I have this JavaScipt code

    Code:
    quizbg.onload = function(){ 
    	context.drawImage(quizbg, 0, 0);
    	SetQuestions();
    }
    and I just simply want to put this jQuery code in it so the audio stops once the bg is loaded (just like it sets the question etc...)

    Code:
    $.each($('audio'), function () {
    this.stop();
    });
    Well yeah that's pretty much it but I really don't understand?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,666
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    jQuery is JavaScript so there is no problem in putting the second script inside the first one (as long as you are loading the core framework first).

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    81
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Mhh so what do you exactly mean by "as long as you are loading the core framework first"?

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,666
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    jQuery is a set of premade JavaScript functions, a JS library/framework, to ease writing scripts. But the browser doesn’t know by itself what you mean when you write something like $('#example'), because that’s not a native JavaScript function. Very simply spoken, someone has written some code that converts long winded native JS functions like document.getElementById('example') to $('example') so you can address elements more easily. And the (JavaScript) code that does this conversion needs to be referenced before $('#example') can be used.

    So, whenever you write/use jQuery you need to reference the core framework that defines the functions before you can use them:
    Code:
    <script src="some_plain_javascript_that_is_not_jquery.js" type="text/javascript">
    <script src="jquery-1.9.1.min.js" type="text/javascript">
    <!-- if you use jQuery scripts they must come after the above reference to the jQuery framework itself; but of course you can also include plain native JavaScript there -->
    <script src="my_custom_scripts.js" type="text/javascript">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •