1
I want to add a class to a link in a list, I got it, but I want to remove the class when I click on another link in the same list, and that the class stays only on the link clicked. add me but when I click on another link, the link previously clicked remains with the class. What I’m doing wrong???
HTML
<li class="list-group-item">
<a onclick="requestFile(this.id)" id="{{ content.id}}">
<!--Colocar o status do log-->
<span class=""></span>
<!--Colocar o status do log-->
<div class="media">
<div class="media-left">
<img class="icon-son-play" src="{% static "img/icons/play-gray.png" %}" alt="">
</div>
<div class="media-body">
<h4 class="media-heading">{{ content.name}}</h4>
{{ content.description}}
</div>
</div>
</a>
Jquery
$(document).on('click', '.page_video_content ul li a', function() {
$('.page_video_content ul li a span').removeClass('started');
$('span', this).addClass('started');
if($('span.started', this)) {
$('span.started', this).css({
'background': '#f3c03d'
}).text("Assistindo");
}
});
You can show your HTML?
– Sergio
Also note that
if($('span.started', this)) {
will always come true. You must use.length
to know if a jQuery collection is empty or not.– Sergio
Only this snippet of HTML does not show all the elements involved in the @Candido question
– Jhonny Mesquita
Can you merge the rendered HTML? ie what appears in the browser when this script runs?
– Sergio
Sergio, I’m sorry, but I can’t, it’s a work thing, I shouldn’t even be asking, but this is really pissing me off... I’m sorry, and thank you for your understanding...
– José
You want the class to be removed, but the orange background can be on the previous link?
– Jhonny Mesquita
I identified that when I click on another link, the background should also pass to another link, right?
– Jhonny Mesquita
@Candido I understand. You can create an example in jsFiddle with similar code that reproduces the problem. That’s simple jQuery, it’s just a matter of seeing your HTML to be able to give an example and explain.
– Sergio
Hello Jhonnyjks, tbm not, the background will be removed tbm...
– José
See my answer below!
– Jhonny Mesquita
Thank you Sergio, for your attention, They are people like you, who deicham this world better!!!
– José
Thanks Jhonnyjks! You helped me a lot! What I said to Sergio is good for you too, Vlu Cara!!!!
– José
@Candido the answer accepted "help" or "solve" the problem? I still think the problem has not been described so we can reproduce...
– Sergio
@Sergio, it worked out, what I wanted! My only problem now is to remove the text "Watching", but this I will do still!!! Thanks!!!
– José
Add
$('.started').text("Assistir");
After the line q hasremoveClass(
– Jhonny Mesquita