0

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"/>
 <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>
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
Ankur
  • 50,282
  • 110
  • 242
  • 312

3 Answers3

2

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"/>

to:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
Alastair Pitts
  • 19,423
  • 9
  • 68
  • 97
1

Instead of:

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

Try:

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

Here's the reason why.

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

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks the end script tag was what I needed. I copied the div names into the question incorrectly. Will edit now. – Ankur Oct 31 '10 at 09:03
0

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
  • 2,725
  • 3
  • 30
  • 36
  • Why is it "better" to serve jQuery locally, and not take advantage of Google's CDN, and potential caching? – David Thomas Oct 31 '10 at 16:45
  • 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 Oct 31 '10 at 20:53