Question

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?

Was it helpful?

Solution

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

$(document).ready(function () {
    $("button").click(function () {
        $("#main").slideToggle();
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top