如何在点击事件时删除类

How to remove a class on click event?

本文关键字:删除 事件      更新时间:2023-09-26

HTML:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script type="text/javascript" src="app.js"></script> 
    <title>Prueba</title>
</head>
<body>
    <div class="prueba"></div>
</body>
</html>

.CSS:

.prueba {
    height: 100px;
    width: 100px;
    background-color: green;
}

JS(已编辑):

var main = function() {
    $('.prueba').click(function() {
        $(this).removeClass('.prueba');
    });
};
$(document).ready(main); 

它(仍然)不起作用。有人可以帮助我吗?

要选择类,您应该在类名前面加上一个点:

$('.prueba')

您可能想要查看的 JQuery 文档。