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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble linking jQuery to HTML

    Hi everyone, trying to practice making websites (recently just started learning to code) and i have a problem, my jQuery commands wont execute on the webpage when i run the html file.
    HTML:
    <!DOCTYPE html>
    <html>
    <head>
    <title> Stuff: Home of all cool stuff!</title>
    <link href="website1stylesheet.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script type="text/javascript" src="website1_java.js"></script>
    </head>

    and heres the jQuery:
    $(document).ready(function() {
    $(img).click(function() ;
    $(this).fadeOut(2000) ;
    });

    If anyone could point the flaw in my code it would be REALLY appreciated

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,092
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Code:
    $(document).ready(function() {
    	$(img).click(function(){
    		$(this).fadeOut(2000) ;
    	});
    });
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    You should start learning how to debug javascript using the dev tools (F12).

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,636
    Thanks
    6
    Thanked 1,003 Times in 976 Posts
    Save the $(document).ready(function() {…}), you can just write $(function() {…});, it’s more concise and does the same.

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    you're missing the qoutes




    Code:
    $(document).ready(function() {
    $('img').click(function() ;
    $(this).fadeOut(2000) ;
    });

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by VIPStephan View Post
    Save the $(document).ready(function() {…}), you can just write $(function() {…});, it’s more concise and does the same.
    Yeah that's more concise but note that using that method is slower than directly using ready() method. The function parameter in the $ method is the last to be checked - $() first checks for selector, then DOM, then function.

    You can see the jQuery source here for your reference:

    http://james.padolsey.com/jquery/#v=1.10.2&fn=init
    http://james.padolsey.com/jquery/#v=...n=jQuery.ready


  •  

    Posting Permissions

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