我有以下代码显示嵌套的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)
$('#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)