cannot read property 'src' of undefined


Staff member
I get the error from the title in the follow JS:

$('.videoMedia .youtubeLink').each(function(i) {
 // Defining the iframe for each iteration
 var iframe = $(this).parents('li').find('.portfolio_det iframe');

 // Cutting the src from the iframe in pieces
 var begin = ''.length;
 var end = iframe[0].src.length-'?fs=1&feature=oembed'.length;

<strong>Uncaught TypeError: Cannot read property 'src' of undefined</strong>

 // Substracting the pieces
 var videolink = iframe[0].src.substring(begin,end);

 // Replacing the link with the leftovers
 $(this).attr('href', '' + videolink); 

     // Removing the iframe

Any ideas why it thinks its undefined? Since iframe is defined on top of the function. Suggestions are welcome :)


Example of this script in "action" (not sure to call it like this, since there aint any action going on) is seen on: <a href="" rel="nofollow"></a>

Currently it only works for the last element on the right/bottom (with the bdare / youtube img)

<strong>Edit 2</strong>

Strange thing is, it used to work before (on localhost using xampp)

<strong>Edit 3 - problem fixxed</strong>

Hereby I would like to thank all of you who joined this discussion :)
I have found the solution.. Nothing was wrong with my code at all :)
The input from the wordpress post provoked the script from running properly, changing the content of the posts fixxed the problem :)

Cheers :)