高亮显示div onclick [英] Highlight div onclick
问题描述
我有一个问题,需要使用什么jQuery代码,点击列表中突出显示DIV?我有8个Div,我需要突出显示一个点击,当点击下一个,以前不再突出显示。
I have a question, what jQuery code need to be used, to highlight DIV in list on click? I have 8 Div's, I need to highlight one which is clicked, and when clicking on next one, previous is no longer highlighted.
推荐答案
p> Ok,所以试试这个: -
Ok, So try this:-
JSFiddle- http://jsfiddle.net/dtzjN/198/
JSFiddle- http://jsfiddle.net/dtzjN/198/
所有您需要做的是,在所有div中都有一个公共类,从每个其他div中删除颜色类,并为点击的div添加颜色类。
All you need to do is, have a common class in all the divs, on click, remove the color class from every other div, and add a color class to the clicked div.
<div class="divs">
Thumb1
</div>
<div class="divs">
Thumb1
</div>
<div class="divs">
Thumb1
</div>
<div class="divs">
Thumb1
</div>
JS
var addclass = 'color';
var $cols = $('.divs').click(function(e) {
$cols.removeClass(addclass);
$(this).addClass(addclass);
});
CSS
.color {
background-color: yellow;
}
source: - 如何用jquery突出显示所选的列表项?
source :- How can I highlight a selected list item with jquery?
根据需要修改它。
这篇关于高亮显示div onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!