Skip to content

Use jQuery on a DOM Object Created on the Fly

by on June 20, 2012

So let’s say you have an item which is created by jQuery (in this case a Google Feed created with Malsup’s jquery.gfeed script).

I want the feed title links of the articles to open in a new window, but do not have direct access to alter the script, or perhaps I simply do not have the time. Another option is to use the live() event handler attachment.

This allows you to act on items which were not loaded when document.ready was run. It could be applied to items created through other means, such as json or javascript. If you find pageLoad() or just keeping the script outside the document.ready call is not working, this may be the solution.

$(‘a.gf-title’).live("click", function(event){
             $(this).attr(‘target’,’_blank’);
});

Advertisements

From → JavaScript, jQuery

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: