cannot read property 'src' of undefined

admin

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

Code:
$('.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 = 'http://www.youtube.com/embed/'.length;
 var end = iframe[0].src.length-'?fs=1&feature=oembed'.length;

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

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

 // Replacing the link with the leftovers
 $(this).attr('href', 'http://www.youtube.com/watch?v=' + videolink); 

     // Removing the iframe
 $(iframe).remove();
});

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

<strong>Edit</strong>

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="http://sqps.nl/bdare/?page_id=279" rel="nofollow">http://sqps.nl/bdare/?page_id=279</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 :)