[Javascript] jQuery: toggle() method not working

Hassan Schroeder hassan at webtuitive.com
Tue Nov 16 10:01:39 CST 2010


On 11/16/10 7:27 AM, Andre Polykanine wrote:

> <script type="text/javascript">
> $("#showBookmark").click(function(e) {
> $("#bookmark").toggle();
> e.preventDefault();
> });
> </script>
> <a href="#" class="menu" id="showBookmark">Show/hide social bookmarks</a>
> <div id="bookmark" class="main" style="display:none"><?=$knopka?></div>
>
> That doesn't work. What am I doing wrong?

Defining "doesn't work" would be a good idea -- are you using e.g.
Firebug and seeing an error, or _______ ?

Regardless, if the above is a literal copy/paste, you're trying to
assign an event handler to an object that doesn't yet exist. Move
the script block after the markup, or enclose the js assignment in
a document.ready block.

HTH,
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
webtuitive design ===  (+1) 408-621-3445   === http://webtuitive.com
twitter: @hassan
                           dream.  code.


More information about the Javascript mailing list