I see you're using jQuery. It's not meant to be used in that manner. The event object you are passing is the browser's native event object. jQuery's event object provides a stopPropagation function.
To use jQuery appropriately, you must let jQuery bind the event instead of doing it inline.
<a href="#" class="openVideo" data-video="videoID" >Watch the video</a>
<script type='text/javascript'>
$(document).ready(function() {
$(".openVideo").click(function(ev) {
ev.preventDefault();
ev.stopPropagation();
var videoID = $(this).data('video');
$(this).append("<iframe width='360' height='315' src='http://www.youtube.com/embed/"+videoID+"' frameborder='0' allowfullscreen></iframe>");
});
});
</script>
Edit: with jQuery 1.4.3 or above you can use a delegate so you don't have to attach the event directly to the anchor but to one of its ancestors. (jQuery 1.7 uses the .on
method to achieve the same thing).
Here is an example using jQuery 1.7:
http://jsfiddle.net/Tu9Hm/
<a href="#" class="openVideo" data-video="videoID" >Watch the video</a>
<script type='text/javascript'>
$(document).ready(function() {
$(document).on('click', '.openVideo', function(ev) {
ev.preventDefault();
ev.stopPropagation();
var videoID = $(this).data('video');
$(this).append("<iframe width='360' height='315' src='http://www.youtube.com/embed/"+videoID+"' frameborder='0' allowfullscreen></iframe>");
});
});
</script>
You pay a small performance penalty using delegates, so try to place the event on the lowest possible element in the DOM. Also, if you place the delegate on the document, you can't really stopPropagation since it has already reached the top, although I believe you're really more concerned about preventDefault()