how can properly execute an if statement after bind()
event
it appears my code wont execute the if statement on the initial paste
of youtube link in my input field.
here is my http://jsfiddle.net/6Z3xP/1/
this only works when i paste the link twice consecutively.
$(document).ready(function () {
var textval = $('#input');
var youtube = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i;
$("#input").bind('paste', function () {
if (youtube.test(textval.val())) {
var yurl = textval.val().match(youtube)[0];
alert(yurl);
}
});
});
i tried adding $(document).ready(function()
right after the binding. but i cant seem to make it work.
background info: i want to capture a youtube url upon pasting a youtube link from a user