Js in the browser console works, but not from the file.
jQuery(document).ready(function(){ $('.sf-with-ul').click(function(){ console.log('clicked'); }); }); Js in the browser console works, but not from the file.
jQuery(document).ready(function(){ $('.sf-with-ul').click(function(){ console.log('clicked'); }); }); Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
Possible reasons for the error:
Try this:
console.log($); // Проверка, загружена ли вообще jQuery $(document).on('click', '.sf-with-ul', function() { console.log('clicked'); }); Perhaps this element appears on the page after loading via AJAX . Try this:
$(function(){ // тот же $(document).ready(), но короче $(document).on('click', '.sf-with-ul', function(event){ // вешаем событие на документ, что бы все добавленные элементы в процессе работы то же обрабатывались console.log('clicked'); }); }); There are no errors in the console? Maybe you connect jQuery later your script?
Source: https://ru.stackoverflow.com/questions/254398/
All Articles