This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I am trying to add a class to a tag html via jquery but something is going wrong I get the element but it's not adding the class I don't get what I am missing:
//HTMl
<ul class="cm-nav-list">
<li class="cm-nav-list\\\_\\\_item cm-nav-list\\\_\\\_item--item1 is-active">
<span class="span1">Label1</span>
<span class="span2">Label2</span>
</li>
<li class="cm-nav-list\\\_\\\_item cm-nav-list\\\_\\\_item--item2">
<span class="span1">Label1</span>
<span class="span2">Label2</span>
</li>
<li class="cm-nav-list\\\_\\\_item cm-nav-list\\\_\\\_item--item3">
<span class="span1">Label1</span>
<span class="span2">Label2</span>
</li>
<li class="cm-nav-list\\\_\\\_item cm-nav-list\\\_\\\_item--item4">
<span class="span1">Label1</span>
<span class="span2">Label2</span>
</li>
<li class="cm-nav-list\\\_\\\_item cm-nav-list\\\_\\\_item--item5">
<span class="span1">Label1</span>
<span class="span2">Label2</span>
</li>
<li class="cm-nav-list\\\_\\\_item cm-nav-list\\\_\\\_item--item6">
<span class="span1">Label1</span>
<span class="span2">Label2</span>
</li>
</ul>
//JS
function selectSquare() {
var me = $(this);
meIndex = me.index();
var selectedItem = me.eq(meIndex);
console.log(selectedItem);
selectedItem.addClass("is-active");
}
function init() {
var label = $(".cm-nav-list__item");
label.click(selectSquare);
}
$(document).ready(init);
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/jquery/comm...