Sunday 15 March 2015

javascript - jQuery not logging event or performing function -



javascript - jQuery not logging event or performing function -

$('.logotop').on('click', 'img', function (event) { console.log(event); if ($(".navtop").css("top", "-100px")) { $(".navtop").css("top", "0px"); } else{ $(".navtop").css("top", "-100px") } });

this code, .logotop image, when click on it, nil happpens & console not log event.

edit: function contained within $(document).ready() , other functions working properly.

note: utilize other jquery functions add together & remove class names before function.

if .logotop class of image never fire, because saying :

in element class name logotop find image , wait click event.

there no image within image tag, code should

$('body').on('click', '.logotop', function (event) { console.log(event); if ($(".navtop").css("top", "-100px")) { $(".navtop").css("top", "0px"); } else{ $(".navtop").css("top", "-100px") } });

or (note first illustration work dynamically created elements)

$('.logotop').on('click', function (event) { console.log(event); if ($(".navtop").css("top", "-100px")) { $(".navtop").css("top", "0px"); } else{ $(".navtop").css("top", "-100px") } });

javascript jquery javascript-events click

No comments:

Post a Comment