3
In the code below comes demonstrating a div
clickable in case it is mobile. When you go full has an icon that appears inside the div
when passing the mouse over, hover
.
HTML
<div class="item" data-filter="{!! $prod->id_categoria !!}" data-categ="{!! $prod->slug_categoria !!}" data-slug="{!!
$prod->slug !!}">
<div class="imagem">
{!! HTML::image('img/produtos/'.$prod->imagem, $prod->produto) !!}
</div>
<div class="icons">
{!! HTML::image('img/details.png', 'Ver Produto', ['class' => 'detail']) !!}
{!! HTML::image('img/add-cart.png', 'Adicionar ao Orçamento', ['class' => 'add-cart']) !!}
</div>
<div class="nome">{!! $prod->produto !!}</div>
</div>
The code that makes the click function is the one below. I tried to use the following syntax:
$(elemento-principal).not(elemento).on()
I meant, when you click on div
with the exception of the icon add-cart
direct me to the product page.
JS
// Seleciona Produto
$('.item').not('.item > .icons > .add-cart').on(clickDeviceEvent, function(){
var prod = $(this).data('filter');
var catg = $(this).data('categ');
var slug = $(this).data('slug');
document.location.href = urlBase + '/produtos/'+catg+'/'+slug;
});
It didn’t work. I don’t know how you do it or if it’s possible to do it.
I want to click on the link inside div
, but that does not turn the function.
I managed to make a way here and I would like to know if it is correct or if there is another way to do.
The reason I wanted the above solution is that I needed to apply another function to the icon. So I created the function now:
// Add Produto ao Orçamento
$('.item > .icons > .add-cart').on(clickDeviceEvent, function(){
console.log('Vixi');
return false;
});
It worked! But it worked because I put the return false
. Then when I click on the icon inside div
, rotates this function first. And with the return false
does not allow the function of the div
.
It worked, but this is the best way ? Or this way is good ?