<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").toggle(function(){
$("p").hide();},
function(){
$("p").show();}
});
});
</script>
</head>
<body>
<p>Click me to toggle between different background colors.</p>
<button>click me</button>
</body>
</html>
i am trying to toggle between hide and show on button click…but it’s not working
a little help will be appreciable
You have a
SyntaxError. Don’t forget to close the parenthesis after the closing brace oftoggle().If you are only toggling the visibility of the element, you should just be able to use
toggle()with no arguments.jsFiddle.