简体   繁体   English

Jquery - 单击jquery函数生成的元素

[英]Jquery - click on element generated by jquery function

I have a jquery slider ( nivo slider ) that generates the next and prev button with jquery. 我有一个jquery滑块( nivo滑块 ),它使用jquery生成next和prev按钮。 I'm trying to add a hide() action for a div on that buttons. 我正在尝试为这些按钮上的div添加一个hide()动作。

$(document).ready(function(){
   $(".nivo-prevNav").live('click', function() {
      $("#slide3").hide();
   });
});

.nivo-prevNav class is generated by the jquery function of slider .nivo-prevNav类由slider的jquery函数生成

Any ideas on how I can fix this because it is not working 关于如何解决这个问题的任何想法,因为它不起作用

.live() has been deprecated. .live()已被弃用。 Use .on() instead: 使用.on()代替:

$(document).on("click", ".nivo-prevNav", function() {
     $("#slide3").hide();
});

For better performance, you should call .on() on the closest parent that's available before the Nivo plugin runs: 为了获得更好的性能,您应该在Nivo插件运行之前在最近的父级上调用.on()

$("#nivo-wrapper").on("click", ".nivo-prevNav", function() {
     $("#slide3").hide();
});

You should change #nivo-wrapper to whatever element you're calling the Nivo Slider on. 您应该将#nivo-wrapper更改为您正在调用Nivo Slider的任何元素。

Are you getting any JavaScript errors? 你收到任何JavaScript错误吗?

$(document).ready(function(){
          $(document).on("click", ".nivo-prevNav", function() {
              $("#slide3").hide();
              });
        });

Change "live" to "on". 将“live”更改为“on”。 Live is depreciated in the newest version of jQuery. Live在最新版本的jQuery中被折旧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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