jQuery Targets for External Links in XHTML 1.0 Strict


/ Published in: jQuery
Save to your folder(s)

XHTML 1.0 Strict does not allow the target attribute on links. The recommended way of specifying external links is to give the link a rel attribute of "external". This jQuery snippet finds likes with rel attributes of "external" and dynamically adds a target attribute of "_blank" so they will open in a new tab/window while maintaining valid XHTML 1.0 Strict code.


Copy this code and paste it in your HTML
  1. $(document).ready(function () {
  2. $('a[rel~=external]').attr('target', '_blank');
  3. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.