开发者

Do I have to have a function triggered by .click when using the pulsate effect in jquery?

I'm trying to figure out why this code

     $(document).ready(function() {
     $(".image2_template").effect( "pulsate", 
      {times:5}, 3000 );
  });

doesn't work yet this

        $(document).ready(function() {

  $("#text4").click(function(){
     $(".image2_template").effect( "pulsate", 
      {times:5}, 3000 );
  });

  });

work fine. Does the pulsate effect have to be triggered by a click? I want it to run on the page load.

UPDATE: After lis开发者_如何学JAVAtening to everyone's helpful suggestions I found out that the element is recognized as an object, but it is says there are no matched DOM elements when I use bjorn's mwthod. How can I resolve this issue?


No, you do not have to trigger it by an event such as click.
It should work as well just by calling the method.
Here is a live example of your working script.


Nothing is wrong in this Script:

        $(document).ready(function() {    
          $(".image2_template").effect( "pulsate", 
          {times:5}, 3000 );   
       });

paste the HTML, maybe your ".image2_template" is rendering after , that is why it did not catch this


You have probably not selected your element properly. Try passing it to a var and then log it using your console to see if you have it properly selected.

var image_template = $(".image2_template");
console.log(image_template.length);

EDIT: Yep @Björn, your right. Edited it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜