[英]How to add icon with jquery?
I have this navigation and this script where i add active class on click. 我有这个导航和这个脚本,我在点击时添加活动类。 I want to add also icon so when user click on icon to get class active and also to have icon inside
<a href=""></a>
. 我想添加图标,以便用户点击图标以激活课程,并在
<a href=""></a>
图标。 This the icon that i want to add: 这是我要添加的图标:
<i class="fa fa-angle-right"></i>
<nav class="right-content-links">
<ul>
<li><a href="/permanent-galleries" class="active">PERMANENT GALERIES</a></li>
<li><a href="/exhibitions">EXHIBITIONS</a></li>
<li><a href="/items">ITEMS</a></li>
<li><a href="/events">EVENTS</a></li>
<li><a href="/coming-soon">COMING SOON</a></li>
<li><a href="/news">NEWS</a></li>
</ul>
</nav>
$(function() {
var href = window.location.href;
$('nav a').each(function(e,i) {
if (href.indexOf($(this).attr('href')) >= 0) {
$(this).addClass('active');
}
});
});
你可以这样做:
$(this).addClass('active').append('<i class="fa fa-angle-right"></i>');
You should do 你应该做
$(function() {
var href = window.location.href;
$('nav a').each(function(e,i) {
if (href.indexOf($(this).attr('href')) >= 0) {
//append icon here
$(this).addClass('active').append('<i class="fa fa-angle-right"></i>');
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.