Last Updated: October 12, 2018
· mateuszgachowski

IE bug when changing href with JavaScript

When you attempt to change the href of an anchor in IE (when the text value contains chars that may tell its an anchor, eg. @, http://) the text value will be changed, as well.


<a href=""></a>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
    $('document').ready(function () {
        $('a').attr('href', '');

On all browsers just the href changes - anchor text stays the same -
On IE the anchor text changes for the same value as its href -

To prevent this issue on IE you can try to append invisible HTML entity, such as for example


to break IE regexp.

Thats all!

1 Response
Add your response

Thank you for your answer @oelmekki!

Maybe you're right, that this is a feature not a bug (:]), but if so - why other browsers don't do that? In fact - when you want to add some malicious code there is no problem to use the workaround that I have mentioned - so thats a poor security feature in my opinion.
And also, as far as I know in IE 10 this does not work anymore.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post a tip