All of the code samples have now been consolidated and moved to my blog at http://house9.blogspot.com/. Many google searches still point here so I am leaving this blog operational.

Friday, September 25, 2009

Attribute "target" exists, but can not be used for this element.

These days I am all about valid xhtml and was surprised to receive this validation error when using the target attribute on an anchor tag.
Attribute "target" exists, but can not be used for this element.


I found a nice work around that does not involve window.open, using jquery we can hack the attribute on 'after' the dom has loaded.



Now instead of target='_blank' you can just use class='target-blank', if the browser does not support javascript it will not open in a new window but the link will still work - and we have our valid xhtml.

Resources

2 comments:

Anonymous said...

Do not forget to add a link to jquery lib ;)

House 9 said...

good point! link to jquery has been added

Custom Search
< ... back