2

I have dynamically created elements on my page. I want these elements to be pulstated using the $(element).pulsate()

The thing is it doesn't work because they we created after running the page load. I've notices there is a jquery .live() command. How do I run the pulsate() under the live command?

4

2 回答 2

1

If you need to make it pulsate based on the click event, you can use .on():

$(container).on('click', selector, function() {
    $(this).pulsate(...);
});

The use of .live() has been deprecated since 1.7

Where container is an element up in the DOM tree that's not removed while your app is running and selector is the relative query (anchored to the container) that's used to match elements you wish to pulsate when clicked.

Example

<div id="container"></div>

Some code would append a new element.

$('#container').append('<div class="bla">bla</div>');

Then this code could be used to achieve what you want:

$('#container').on('click', '.bla', function() {
    $(this).pulsate(...);
});
于 2012-12-23T07:17:25.580 回答
0

The thing is it doesn't work because they we created after running the page load.

So use $(element).pulsate(); with an appropriate selector or element instances after you've created the elements. You haven't said how/when you're creating them, so I don't know whether it's on an event or a timer or what, but either way eventually you have code running that creates the elements. So tell them to pulsate as part of that code. E.g.:

/* ...add a bunch of content to #foo... */
$("#foo").pulsate();

You might use a class when creating the new elements (class="new") so you can just blindly do this:

$(".new").pulsate().removeClass("new");
于 2012-12-23T07:16:57.063 回答