tags:

views:

34

answers:

3

I can't seem to make the "tohide" element hide and thus toggling doesn't work either. Dreamweaver tells me that my error is this line }); which appears under the line $("#mydiv").toggle();

<html>
 <title>Hider</title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"/&gt;
 <script type="text/javascript">
   $(document).ready(function(){
     $('#tohide').hide();
     $("#click").click(function() {
       $("#tohide").toggle();
     })
   });;
 </script>
 </head>
 <body>
   <input type="submit" name="click" id="click" value="Submit" />
   <table id="tohide" width="100">
     <tr>
       <td bgcolor="#00FF33"><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
       </td>
     </tr>
   </table>
 </body>
</html>
+2  A: 

try changing your jquery script import tag to include the </script> end tag.

from:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"/&gt;

to:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
Alastair Pitts
@Alastair what's the difference (real question)
Kevin
@Kevin - A `<script>` tag simply can't be self-closing, different browsers reject it in different ways.
Nick Craver
+1  A: 

Instead of:

<script type="text/javascript" 
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"/&gt;

Try:

<script type="text/javascript" 
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;

Here's the reason why.

Also in the markup you posted there's no element with id="mybutton" nor id="mydiv".

Darin Dimitrov
Thanks the end script tag was what I needed. I copied the div names into the question incorrectly. Will edit now.
Ankur
A: 

Hello,

this is the corrected markup.

<html>
<head>
    <title>Hider</title>
</head>
<body>

    <a href="#" id="link_1">TOGGLE</a>

    <div id="some_id">

        <h1>HELLO</h1>

    </div>


<script src="jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">


    $(document).ready(function() {


        $("#link_1").click(function() {

            $("#some_id").toggle();
            // Act on the event
        });


    });


</script>


</body>

Please note that you also had a error in the calling of the script from google.
It is better to load it locally.

Have a nice day :)

Herr Kaleun
Why is it "better" to serve jQuery locally, and not take advantage of Google's CDN, and potential caching?
David Thomas
You never know, what if google's CDN fails one day? Even google itself can fail, facebook fails, twitter fails. If your server can serve the files, then it will server your jQuery too. :)
Herr Kaleun