Reputation: 243
I've been trying to hide/show button by using Toggle jQuery. But when I clicked the event didn't happen.
<script>
$(document).ready(function () {
$("button").click(function () {
var main = this.value;
$("#" + main).slideToggle();
});
});
</script>
A div:
<div id="main">
@RenderBody()
<button>Toggle</button>
</div>
Could anyone tell me what happened with these lines of code?
Upvotes: 0
Views: 67
Reputation: 38102
Your button does not have any value attribute, seem like you want:
$(document).ready(function () {
$("button").click(function () {
$("#main").slideToggle();
});
});
Upvotes: 1