문제

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?

도움이 되었습니까?

해결책

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

$(document).ready(function () {
    $("button").click(function () {
        $("#main").slideToggle();
    });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top