I'm attempting to add target="_blank" to an a tag that I've wrapped around an ID for a column containing a number of elements.
I've tried adding the attribute target="blank", but it doesn't appear to be working.
Here is the column I've wrapped with an a tag.
<div id="loyaltycol1"> This is some text. <img src="#" alt="A Picture" /> </div> Here is the javascript code.
jQuery(function($) { $("#loyaltycol1").wrap("<a href='www.examplesite.com'></a>").attr('target','_blank'); }); How can I get the a tag to have target="_blank"?
#loyaltycol1, not#loyatycol1(missing 'l'). Secondly, wrap returns the original#loyaltycol1element, not thea, so you're adding the attribute to the wrong element. Use.parent().attr(.... That being said, if you're hard-coding theaanyway, just add the attribute in the HTML string.jQuery(function($) { .parent(#loyaltycol1).attr('target','blank'); });Where would the wrap for the a tag come in?.wrap("<a>").parent().attr(...<a href='...'></a>is a custom coded element. As Rory pointed out, if you want the target attribute on that link, just add it to that string. Don't try to force it to be a second operation.