When I click on the item, the function changes the class of this item so that it can be detected by the other function when clicking.
The problem is that when I use .click
, click is normally detected, but when I click again (already with the class changed), it does not detect this click .
And when I use .on
, it does not work even when I click 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 causing conflict is this stopPropagation()
, but I'm not sure. Would you have some way around this?
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');
});