Trung Pham
Trung Pham

Reputation: 243

How to use Toggle button jQuery in <div main..>

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

Answers (1)

Felix
Felix

Reputation: 38102

Your button does not have any value attribute, seem like you want:

$(document).ready(function () {
    $("button").click(function () {
        $("#main").slideToggle();
    });
});

Upvotes: 1

Related Questions