views:

44

answers:

1

I made a web page that uses jQuery: http://benmccormack.com/demo/MichaelMassPsalm/Psalm16Mode5.html

When you change the selection in the combo box from Higher Key to Lower Key, all of the music images are supposed to change their source to be images that represent the lower key signature. This works great in IE8, but it won't work in Safari, Firefox, or Chrome.

Why not?


Here's the jQuery code that I'm using:

$(document).ready(function () {
    $("#musicKey").change(function (event) {
        if ($("#musicKey").val() * 1) {
            $("img[src*='Low'").each(function (index) {
                $(this).attr("src", $(this).attr("src").replace("Low", "High"));
            });
        }
        else {
            $("img[src*='High'").each(function (index) {
                $(this).attr("src", $(this).attr("src").replace("High", "Low"));
            });
        }
    });
});
+4  A: 

You're missing closing brackets on your attribute-contains selectors:

$("img[src*='Low']")
//and...
$("img[src*='High']")

At the moment, that invalid selector just isn't finding anything, so nothing to execute on.

Nick Craver
So thaaaat's what you do with IE, you trick it into doing what you want it to do.
Babiker
@Babiker - Until it eats your cat, smashes your car, bangs your woman and steals your best friend, or maybe that was Lotus Notes, I can't keep them straight anymore...
Nick Craver
@Nick Bingo. That was it. I guess IE8 is a lot more forgiving. Also, I prefer IE8's behaviour on the `change` event. The event fires once you pick a different option. On the other browsers, you have to move focus before the event fires, which is annoying.
Ben McCormack
@Ben - You can do `.bind('click change', function...` here instead of `.change(function...` given the operation you're doing :)
Nick Craver
@Nick Craver. `.bangWife()` this mysteriously worked in IE.
Babiker