Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the wrong in this code?

Hi everyone I am a new to jQuery. While learning I am following this link: http://api.jquery.com/browser/. When I am trying to do this example in VS 2010 I'm not getting the exact output. But when I was copying the code which is in this link I was getting the correct output. Please could any one help me?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <base href="http://docs.jquery.com" />
        <title>index(subject) function</title>
        <style type="text/css">
            .div_style
            {
                background-color: Aqua;
                font-family: Verdana;
                font-size: small;
            }
        </style>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js" />
        <script type="text/javascript">
            $(document).ready(function () {
                $("div.div_style").click(function () {

                    //This is the DOM element clicked
                    var index = $("div").index(this);
                    $("span").text("That was div index #" + index);
                });
            });
        </script>
    </head>
    <body>
        <span></span>
        <br />
        <div class="div_style ">
            First Div
        </div>
        <br />
        <div class="div_style ">
            Second Div
        </div>
        <br />
        <div class="div_style ">
            Third Div
        </div>
        <br />
    </body>
</html>
like image 323
Hemant Kumar Avatar asked Mar 23 '26 20:03

Hemant Kumar


1 Answers

You can't use self closing tags for <script>. You must end with a </script>:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
like image 51
David Tang Avatar answered Mar 25 '26 08:03

David Tang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!