I want to add some HTML to the end of every youtube link to open up the player in a litebox. This is my code so far:
$(document).ready(function() {
var valid_url = new RegExp('youtube.com/.*v=([a-zA-Z0-9_-]+)');
var image_data = 'base64 encoded image';
init();
function init() {
$('a').each(function() {
if (valid_url.test($(this).attr('href'))) {
$(this).after( ' <img src="' + image_data + '" onclick="open_litebox('hi');" />' );
}
});
}
function open_litebox(param) {
alert(param);
}
});
It works to the point where it injects some HTML after the youtube link, like so:
<img src="base 64 data" onclick="open_litebox('hi')">
But when I click this the open_litebox()
function doesn't get called. Looking in the error console I can see an error that says open_litebox is not defined
, but I have defined it.
I'm pretty clueless as to what's going wrong here, could someone lend me a hand?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…