jquery target=_blank doesnt work
I have this piece of code:
$('.tool li a:first-child').each(function(){
$(this).after(' <a href="' + $(this).attr('href') + '" title="Open l开发者_C百科ink in new tab"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" target="_blank" /></a>');
});
So even though the images that are added are hyperlinked with a target=_blank, the link does not open in a new window.
Any thoughts why the browser does not recognize that?
-Ryan
You need to add the target
attribute on the a
tag, not the img
tag.
$('.tool li a:first-child').each(function(){
$(this).after('<a href="' + $(this).attr('href') + '" title="Open link in new tab" target="_blank"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" /></a>');
});
target="_blank" should be an attribute for the anchor tag
Replace:
$(this).after(' <a href="' + $(this).attr('href') + '" title="Open link in new tab"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" target="_blank" /></a>');
With:
$(this).after(' <a href="' + $(this).attr('href') + '" target="_blank" title="Open link in new tab"><img src="/img/icon-arrow.png" height="9" width="9" alt="Arrow Icon" /></a>');
精彩评论