简体   繁体   中英

jQuery .click() doesn't fire on particular element

I'm trying to register when someone clicks on an arrow (it appears when you hover over the floating box) that moves from one slide to another on the main page of this site: http://questtours-dc.com but for some reason the arrows are a black hole.

I have multiple functions setup to log clicks at the moment trying to figure this out. It is a Wordpress site so I have to pass the $ in.

jQuery(document).ready(function($) {
  $(document).click(function(){
    console.log(' A click has occurred ');
  });

  $(".et-arrow-next").click(function(){
    console.log(' You clicked the arrow ');
  });

  $(".et-slider-arrows").on('click','.et-arrow-next',function(){
    console.log(' 1 - You clicked the arrow ');
  });

  $("a.et-arrow-next").on('click',function(){
    console.log(' 2 - You clicked the arrow ');
  }); 

  $('#et-slider-wrapper').on('click','.et-arrow-next', function() {
    console.log(' 3 - You clicked the arrow');
  });
});

When you click anywhere on the page except the two arrows that come on either side of the floating box it registers a click. But whenever you click on an arrow it registers nothing.

EDIT: This does not work either. Added after first two replies.

$(".et-arrow-next").on("click", function() {
  console.log(' You clicked the arrow '); 
}); 

EDIT 2: Trying to target the class after the hover has kicked in doesn't work either

$('#et-slider-wrapper:hover .et-slider-arrows a').on('click', function() {
  console.log(' 4 - You clicked the arrow ');
});

$('#et-slider-wrapper:hover .et-arrow-next').on('click', function() {
  console.log(' 5 - You clicked the arrow ');
});

If the element you are trying to click is dynamically generated from javascript , use

$( ".et-arrow-next" ).on( "click", function() {
     console.log(' You clicked the arrow ');
});

it appears when you hover over the floating box

If it is appended dynamically to the page (meaning that it doesn't actually exist when the document is ready) then you have to use the on() method like this:

$(".someclass").on("click", function(){
    // your code
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM