如何使用jquery添加/删除类或样式

use*_*293 3 css jquery

我有以下代码显示嵌套的ul并在点击时隐藏其他打开的.我的问题是如何将一个背景图像添加到打开嵌套ul的父li a中,并从它关闭的父li a中删除背景图像?

这是我的jquery:

$(document).ready(function() {
    $('ul ul').hide();

    $('ul li > a').click(function(event) {
        $('ul ul').hide('slow');


        $(this).parent().find('ul').show('slow');
    });

});;
Run Code Online (Sandbox Code Playgroud)

Ton*_*bet 7

$('#item').addClass('myClass');  //will add the class
$('#item').removeClass('myClass'); //will remove the class


$('#item').toggleClass('myClass'); //will toggle the class (add it if doesn't have it or remove it if it does)
Run Code Online (Sandbox Code Playgroud)

和内联样式

$('#item').css({'color':'red','background':'blue'}); //will override those properties
Run Code Online (Sandbox Code Playgroud)