CSS: Prevent parent element getting :active pseudoclass when child element is clicked

后端 未结 12 912
暖寄归人
暖寄归人 2021-01-07 16:19

JSFiddle

When you click the button, you see that :active pseudoclass is triggered for the parent div. Is ther

12条回答
  •  暖寄归人
    2021-01-07 17:04

    try this

    html:

    css script:

    div {
      width: 200px;
      height: 200px;
      background-color: #eee;
      border: 1px solid black;
    }
    .current_active{
      background-color: red;
    }
    

    jquery:

    $("#btnclick").click(function(){
        $("#current").toggleClass("current_active");
    });
    

    JSFiddle

    ps: include the jquery library file

提交回复
热议问题