我的JSP中有这段代码:
<div class="thedescription">
<ul class="descriptionlanguages">
<li id="EN_langLinkLi" class="selectedlanguage" >
<a id="EN_langLink" class="showDifferentLang" href="#">EN</a>
</li>
<li id="IT_langLinkLi" class="notSelectedlanguage" >
<a id="IT_langLink" class="showDifferentLang" href="#">IT</a>
</li>
</ul>
</div>
和脚本,我用来改变整个li的类
<script type="text/javascript">
$(document).ready(function(){
$('li').click(function() {
alert ('lsls');
$('#thedescription ul li ').each(function(){
this.className = 'notSelectedlanguage';
});
});
});
</script>
但不会改变任何东西!
答案 0 :(得分:4)
您可以使用addClass()
添加要点击li
和removeClass()
的课程,以便从兄弟姐妹li
$('li').click(function() {
$(this).addClass('notSelectedlanguage').siblings().removeClass('notSelectedlanguage');
});
.notSelectedlanguage {
background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="thedescription">
<ul class="descriptionlanguages">
<li id="EN_langLinkLi" class="selectedlanguage">
<a id="EN_langLink" class="showDifferentLang" href="#">EN</a>
</li>
<li id="IT_langLinkLi" class="notSelectedlanguage">
<a id="IT_langLink" class="showDifferentLang" href="#">IT</a>
</li>
</ul>
</div>
答案 1 :(得分:1)
您可以尝试--packages
this.className = 'notSelectedlanguage;