0
When I click on the item, the function changes the class this item so it can be detected by the other function when clicking.
The problem is that when I use the .click
, the click is detected normally, but when I click again (already with the class changed), it does not detect this click.
And when I use the .on
, doesn’t even work when I click for the first time.
HTML
<div class="options">
<ul>
<li><a href="#" class="com-estoque">ativar</a></li>
</ul>
</div>
I use the function below to open and close the menu where the link is. I believe that what is giving conflict is this stopPropagation()
, but I’m not sure. There would be some way around this problem?
JS
$(".options").click(function(e) {
$(this).find('ul').toggle();
e.stopPropagation();
});
$(document).on('click', function(e) {
$('.options ul').hide();
});
$('.pagina-produtos-admin').on('click', '.sem-estoque', function(e) {
e.preventDefault();
$(this).parents('.produto').addClass('semestoque');
$(this).removeClass('sem-estoque').addClass('com-estoque').html('ativar');
});
$('.pagina-produtos-admin').on('click', '.com-estoque', function(e) {
e.preventDefault();
$(this).parents('.produto').removeClass('semestoque');
$(this).removeClass('com-estoque').addClass('sem-estoque').html('marcar como fora de estoque');
});
It’s working normal buddy.
– Sam
Now that you mentioned, I went to test in an online editor and it works. I don’t know why it’s not working in my code.
– Diego Vieira