mrVG mrVG - 4 months ago 7
Javascript Question

JQuery click is not working

I have following simple html block:

<span class="change_ordering show-list" data-ordering-by="product_list" data-ordering-direction="desc">By list</span>


Then, I have following js-code:

$(document).ready(function() {
$('.show-list').click(function() {
console.log('qwe');
});
});


When I click on it - nothing happens. But when I paste this js-code to Google Chrome JS console, it works perfectly. JS works fine on my site, I can make other JQuery actions. I also tried to write
$('.change_ordering.show-list')
and
$('span.change_ordering.show-list')
and
$('span.show-list')
, but still no progress. What I'm missing?

EDIT: This element is not drowing by ajax.

Answer

Please apply click using following way

$(document).on("click",".show-list",function(){})

It will work