javascript - jQuery toggle divs not working -
javascript - jQuery toggle divs not working -
i'm trying create 2 divs, , when 1 clicked, hides other. here's code:
<head> <script src="jquery-1.9.1.min.js"></script> <script> $("#top").click(function { $("#box").toggle(); }) </script> </head> <body> <div id="top"></div> <div id="box"></div> </body> but when click on top, nil happens.
edit: changed to:
$(document).ready(function(){ $("#top").click(function { $("#box").toggle(); }) }); and it's still not working
edit2: turns out missing brackets in click(function)
you missing brackets
$("#top").click(function() { ^^ and since jquery above html binding need wrap jquery in document.ready wrapper, example:
$(function(){ // code }); alternatively, move jquery script tag below html, example:
<div id="top">one</div> <div id="box">two</div> <script> $("#top").click(function() { $("#box").toggle(); }) </script> javascript jquery html
Comments
Post a Comment