user2349508 user2349508 - 7 months ago 16
Javascript Question

Click function is not working on $(document)

alert("hi");
$(document).on('click', '.customerstory-section-header', function() {
$('.overlay-Div').hide();
$(this).parent().children().children("div.overlay-Div").toggle();
$("#Jananayak-Stories-Section").hide();
$("#Customer-Stories-Section").show();
});


The
click
function is working on a
div
. The classname selector is the same in markup and here in jQuery code. If I put an
alert
outside the click function, it's working, the alert is coming. If I put alert inside the click function, it's not working.
console
is not working there. Can anybody help me, please?

$(".customerstory-section-header").hover(function(){
alert("hi");
$('.overlay-Div').hide();
$(this).parent().children().children("div.overlay-Div").toggle();
$("#Jananayak-Stories-Section").hide();
$("#Customer-Stories-Section").show();
});


I changed the event hover and just tried. Its not working. if i put alert outside the function, alert is coming. So JS file is loading. But none of the event handler is not working. Please help me here

hmd hmd
Answer

You may need this:

$(function() {
  $( "body" ).click(function() {
    alert( "Body Clicked" );
  });
});

DEMO: http://jsfiddle.net/e640ggmy/

Comments