Youss
Youss

Reputation: 4232

Event click on youtube API

I'm working with Youtube API and Jquery. With a certain script I can get Youtube Feeds as an image, take a look at the example: JsFiddle

I'm trying to do a Jquery click event which will have to invoke another script called 'embedly' like this:

$("a").click(function(event) {
    event.preventDefault();
    $(this).embedly({
    chars: 220,
    nostyle: true,
    key:':41f042ec20b04dda84448dc4a46d357d'
}); 
}); 

It doesn't seem to work. When I do this from my desktop the click does not invoke the embedly part and also goes to the url regardless of the prevent default.

Upvotes: 0

Views: 486

Answers (1)

user1726343
user1726343

Reputation:

You can use event delegation to ensure the handler will be triggered regardless of when the anchor comes into the DOM:

$(document).on("click","a",function(event) {
    event.preventDefault();
    $(this).embedly({
        chars: 220,
        nostyle: true,
        key:':41f042ec20b04dda84448dc4a46d357d'
    });
}); 

http://jsfiddle.net/bfysr/3/

Upvotes: 1

Related Questions