3

Please help, I'm new to web design and want to make the demo below work but it seems my HTML is not linking to my javascript. please view the code below, the demo is also available at http://jsfiddle.net/xx9ykonc/ How do I make it work, I don't understand whats missing.

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>

<table>
    <tr>
        <td><div>1</div></td>
        <td><div>2</div></td>
        <td><div>3</div></td>
        <td><div>4</div></td>
    </tr>            
</table>

<script>
$('table div')
    .on('mouseenter', function(){
        var div = $(this);
        div.stop(true, true).animate({ 
            margin: -10,
            width: "+=20",
            height: "+=20"
        }, 'fast');
    })
    .on('mouseleave', function(){
        var div = $(this);
        div.stop(true, true).animate({ 
            margin: 0,
            width: "-=20",
            height: "-=20"
        }, 'fast');
    })
</script>

</body>
</html>
4
  • 6
    What exactly is the problem? What do you mean by linking? The Fiddle seems to work as intended. Commented Apr 19, 2016 at 10:25
  • 1
    What do you want to happen; what is happening, and what (if any) error messages do you get in the browser console (usually available by pressing F12)? Commented Apr 19, 2016 at 10:26
  • 2
    Add <script src="code.jquery.com/jquery-2.2.3.js"></script> inside the <head> section of your HTML. Then the script should work. Commented Apr 19, 2016 at 10:35
  • 3
    You are using jQuery, but have not included the jquery.js file itself to the HTML. That is why the js code is not working. Commented Apr 19, 2016 at 10:36

3 Answers 3

4

You should include jquery by adding this script in the head of your html page

<head><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script></head>
Sign up to request clarification or add additional context in comments.

1 Comment

To be more specific: OP is using jQuery in his/her <script> tags, and the page does not load any version of the jQuery which is required for any of it to work. JSFiddle I believe has a built-in support for jQuery, and thereby the code might work there just fine, but when moving to localhost or where ever else, it wont.
2

As @Rocker1985 mentioned in the comment, you can link the jquery file to your HTML like which you have already link the CSS file.

<head>
  <link rel="stylesheet" type="text/css" href="style1.css">
  <script script src="~/Scripts/jquery-1.10.2.min.js"></script>
  <script script src="~/Scripts/jquery-ui-1.11.4.min.js"></script>
</head>

Give the exact path and version of jquery file.

1 Comment

-1. The tags in the question is "javascript", "jquery", "html" and "css". It can be assumed that the OP is not using ASP.Net MVC, he is using plain HTML. The "@Url.Content" syntax will not work in plain HTML.
0

in your html you have missed jquery library link just you need to attach source link it will work also you can check the same below

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="style1.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<table>
    <tr>
        <td><div>1</div></td>
        <td><div>2</div></td>
        <td><div>3</div></td>
        <td><div>4</div></td>
    </tr>            
</table>

<script>
$('table div')
    .on('mouseenter', function(){
        var div = $(this);
        div.stop(true, true).animate({ 
            margin: -10,
            width: "+=20",
            height: "+=20"
        }, 'fast');
    })
    .on('mouseleave', function(){
        var div = $(this);
        div.stop(true, true).animate({ 
            margin: 0,
            width: "-=20",
            height: "-=20"
        }, 'fast');
    })
</script>

</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.