osakagreg
osakagreg

Reputation: 577

How can I use jQuery to stop IE from ignoring the hash

Here are my example links:

<div class="aside-box">
<a href="#">test 1</a>
<a href="#login-box" class="login-window">test 2</a>
</div>

Some IE browsers are ignoring the hash. So instead of showing:

<a href="#login-box" class="login-window">

it only shows:

<a href="#" class="login-window">

Is there some jQuery I can add prior to this link to ensure that it is not ignored only in the cases that it has already been stripped?

I am trying to use this, but so far no luck:

<script type="text/javascript">
$('#aside-box a:not([href*="#"])').live('click',function() 
$(this).attr('href', $(this).attr('href') + "#aside-box");        
});
</script>

I have edited this because the above solution (in fact) worked.

The jQuery (above) fixed it. I was under the impression that it did not work, but the person who it affected, just wrote back to me and said that it is working fine now.

It's hard to work with every browser out there.

Upvotes: 1

Views: 125

Answers (2)

osakagreg
osakagreg

Reputation: 577

Turns out the original post had the solution. I just could not recreate the problem, and finally received confirmation that it was in fact working after the jQuery was put in place.

Upvotes: 0

Flash
Flash

Reputation: 16703

Taking a guess at what you mean here, but perhaps your problem is you are trying to target #aside-box when you have it defined as a class and not an id in your HTML (currently your jQuery does that for instance).

Also, some ancient browsers will only follow fragments defined with a name attribute like <a name='foo' id='foo'>.

Other than that, if you click <a href="#foo">bar</a> you will be taken to the element with id foo.

Upvotes: 2

Related Questions