删除上次单击跨度上的图标
Remove icon on last clicked span
问题
我试图只在上次单击的span.highlight
上隐藏Font Awesome"plus"图标,并在没有active
类的跨度上显示它,但现在它正在删除两个跨度上的图标,并且在添加活动类后不会显示。
JSFiddle:http://jsfiddle.net/dg6w2sk2/
scripts.js
$(".highlight").click(function() {
$(".highlight").removeClass("active"); // Remove active class from spans
$(this).addClass("active"); // Add an active class to span just clicked
$(".fa-plus-circle").hide(); // Remove plus sign on active span
$(".info").fadeIn(); // Fade in the info box to the left
});
index.html
<p><span class="highlight underline active" title="Read about the 'Clutter Hoarding Scale'"><i class="fa fa-plus-circle"></i> Next level church-key Shoreditch brunch</span> readymade. Chia pickled whatever, Blue Bottle farm-to-table messenger bag Neutra disrupt you probably haven't heard of them keytar dreamcatcher biodiesel banjo cardigan. Actually cliche you probably haven't heard of them put a bird on it tattooed, cray Bushwick irony selfies synth lomo gastropub. <span class="highlight underline"><i class="fa fa-plus-circle"></i>Tousled occupy Schlitz Austin.</span></p>
您可以使用这个:
$(".highlight").click(function() {
$(".highlight").removeClass("active"); // Remove active class from spans
$(".fa-plus-circle").show();
$(".info").fadeIn(); // Fade in the info box to the left
var active = $(this).hasClass("active");
/*if (active) {
$(this).find(".fa-plus-circle").hide(); // Remove plus sign on active span
} else {
$(this).find(".fa-plus-circle").show();
}*/
$(this).addClass("active"); // Add an active class to span just
$(this).find(".fa-plus-circle").hide();
});
此处的示例:http://jsfiddle.net/dg6w2sk2/6/
相关文章:
- 单击更改图标并通过javascript添加一个css类
- 使用Angular单击时更改特定图示符图标的颜色
- 通过单击同一图标使菜单出现和消失
- 如何制作Yii框架的linkHtmlOptions's的CGridView显示为图像图标,单击时会触发javas
- 单击时切换上下图示符图标的问题
- 单击扩展图标时打开popup.html
- Jdewit Timepicker 在文本和图标单击上显示小部件
- 单击标记时更改标记图标(在单击事件上),并在单击另一个标记时将其恢复为普通图标
- 单击图标后编辑信息
- 添加/单击c#asp.netmvc5后禁用和更改按钮图标
- 如何在单击按钮时为整个星形图标上色
- 我是否可以在单击特定图标时更改地图标记图标,然后在单击另一个图标时切换,等等
- 如何在单击图标时渲染图标并调用函数
- 单击时如何更改汉堡菜单图标
- 单击href旁边的链接(删除图标)时删除href(Javascript帮助)
- 单击社交媒体图标(字体真棒)而未重定向到href
- 如果您单击文件夹图标而不仅仅是三角形图标,我如何让 jstree 关闭/打开
- 单击时使用 jquery 更改图标
- AngularJS在图标单击时隐藏引导日期选择器
- 如何在图标单击时激活拖放区