Take the 2-minute tour ×

I am having a problem with this JQuery in ie7, it works perfectly in chrome, firefox, and ie8/9. I've scoured the internets to no avail. It just doesn't want to change the src attribute, which leads me to believe it's failing at the if test.

var active = '/wp-content/uploads/2012/07/active.png';
var inactive = '/wp-content/uploads/2012/07/inactive.png';
if ($(this).attr('src') == inactive) {
    $(this).attr('src', active);
    $('.navbutton').not(this).attr('src', inactive);

The line below works in ie7, outside of an if test, so i'm not exactly sure what the problem is. Anyone know what's going on?

$('#navbutton0').attr('src', active);
share|improve this question
What's $(this), can you post the context? –  elclanrs Jul 23 '12 at 14:35
When you alert($(this).attr('src')), what does it say? –  Blazemonger Jul 23 '12 at 14:38
$(this) is referring to the .navbutton class, the if test is inside of $('.navbutton').each(function(index){ $(this).on("click", function(event){ –  ajc458 Jul 23 '12 at 16:06
sorry I forgot to mention that in the beginning :( –  ajc458 Jul 23 '12 at 16:13
add comment

1 Answer

up vote 1 down vote accepted

Try using $(this).attr('src').indexOf(inactive) >= 0 instead as your if test condition. I think I noticed IE7 was sometimes adding extra stuff to the src, such as the full path.

share|improve this answer
Thank you! It works like a charm :) –  ajc458 Jul 23 '12 at 16:08
add comment

Your Answer


