Search code examples
htmljqueryhideshow

Show HTML div element which has class "hide" in jQuery


I have this simple <div>:

<div id='myId' class='hide'>...</div>

I want to show it using the class show.

$("#myId").show();

It doesn't work, the <div> keeps the hide class.


Solution

  • You can use toggleClass() as follows:

    $("#myId").toggleClass("hide show");
    

    or

    $("#myId").removeClass("hide").addClass("show");