jQuery .clone() refreshes the page in safari
When I call
var newElement = $(someElement).clone();
It refreshes the page immediately in Safari. I use jQuery v1.6.4. and Safari v5.1. In Chrome and Firefox the above call works perfectly.
Here is the code that refreshes the page in safari.
function resetAllAudioPieces()
{
var audioPieces = $(".audio-piece");
audioPieces.each(function(index){
var newElement = $(audioPieces[index]).clone();
$(audioPieces[index]).replaceWith(newElement);
$(audioPieces[index]).removeClass("playing");
$(audioPieces[index]).disableSelection();
});
return;
}
$("a#stop").live('click', function(e){
开发者_C百科resetAllAudioPieces();
e.preventDefault();
});
When I click the "#stop" link, the page refreshes. Is this a bug in jQuery clone() ? Please help.
Can you try without the "return;" and switch the preventDefault position ?
function resetAllAudioPieces()
{
var audioPieces = $(".audio-piece");
audioPieces.each(function(index){
var newElement = $(audioPieces[index]).clone();
$(audioPieces[index]).replaceWith(newElement);
$(audioPieces[index]).removeClass("playing");
$(audioPieces[index]).disableSelection();
});
// return;
}
$("a#stop").live('click', function(e){
e.preventDefault();
resetAllAudioPieces();
});
精彩评论