Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 4
    Firstly it's #loyaltycol1, not #loyatycol1 (missing 'l'). Secondly, wrap returns the original #loyaltycol1 element, not the a, so you're adding the attribute to the wrong element. Use .parent().attr(.... That being said, if you're hard-coding the a anyway, just add the attribute in the HTML string. Commented Aug 27, 2019 at 16:25
  • That was just a typo on my part. It's correct in the site. I'll update it above. I'm not hard coding. I'm trying to add this element to an existing framework that will be maintained by a client, so I'd like to not build out custom coded elements if possible. Sorry, I don't understand what you are suggesting here. Are you saying to do: jQuery(function($) { .parent(#loyaltycol1).attr('target','blank'); }); Where would the wrap for the a tag come in? Commented Aug 27, 2019 at 16:33
  • .wrap("<a>").parent().attr(... Commented Aug 27, 2019 at 16:43
  • "so I'd like to not build out custom coded elements if possible". You aleady are. <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. Commented Aug 27, 2019 at 16:55
  • Yes I already did that but it broke my code. Just figured out what I did wrong. I added target="_blank" rather than target='_blank'. The former broke my jquery which is why I thought it wasn't an option. Commented Aug 27, 2019 at 17:45