Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Ronald Roe

Thread: Simple Jquery not working in index.html file or external.

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Member #
    36934

    Simple Jquery not working in index.html file or external.

    Hello, I've designed a little site using HTML/CSS and i decided to add some Jquery that i learned. Unfortunately I can't figure out how to get it to work.

    I tried linking to an outside script.js file similar the way I do my .css but no luck. Anyways heres the script. I got the code of codeacademy.com because the one I was using wasn't working so I'd figure I would use one from there lessons that worked.

    Also for linking to external I did <script type="text/javascript" src="script.js"> </script>

    sorry if I didn't insert the html properly, I couldn't find a option to do so.


    <!DOCTYPE html>
    <html>
    <head>
    <title>Krypton Redux</title>
    <link rel='stylesheet' type='text/css' href='newcss.css'/>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
    </script>


    </head>
    <body>

    <div> </div>

    <script>
    $(document).ready(function() {
    $('div').mouseenter(function() {
    $(this).animate({
    height: '+=10px'
    });
    });

    $('div').mouseleave(function() {
    $(this).animate({
    height: '-=10px'
    });
    });
    $('div').click(function() {
    $(this).toggle(1000);
    });
    });
    </script>


    </body>
    </html>

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Upload your example somewhere so we can see it.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    You're missing the "http:" in your src for jquery.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Also, you could use .hover() to shorten up your script a bit:
    Code:
    $(function(){           /* Same as $(document).ready(function() */
      $('div').hover(
        function(){$(this).animate({height: '+=10px'});
        },
        function(){$(this).animate({height: '-=10px'});
        });
    });
    Last edited by Ronald Roe; Aug 05th, 2013 at 09:31 AM. Reason: Fixed a minor syntax error.
    davep1234 likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    No he's not. That' done so that the script will still load on encrypted pages (i.e. pages that are of the form https://whatever).
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  7. #6
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by TheGAME1264 View Post
    No he's not. That' done so that the script will still load on encrypted pages (i.e. pages that are of the form https://whatever).
    Was not aware of that. However, when I put the link in that way, the script doesn't work, but if I add the http:, it works fine. But then, I'm just running an HTML file straight from the local disk. Perhaps a server is required?
    Last edited by Ronald Roe; Aug 05th, 2013 at 09:29 AM.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  8. #7
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Maybe. I usually only ever load it from an absolute path just to be paranoid safe anyway.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  9. #8
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Member #
    36934
    Ya i added the http: and it ended up working. Thanks Ronald.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:06 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com