开发者

change icon in ajax menu?

I have 开发者_StackOverflowa menu and when an item is clicked I would like to change the icon to a different color. I got this working by changing the src of the image that is clicked! I change the src images/silver/icon.png to images/blue/icon.png

If I click an item(with a silver color icon), then it changes color to blue(good) but when I click another item the first item is still blue, so after clicking a bit, all items are blue.

So the help I need is how to get ALL image sources but not the one that is clicked, and change them to silver? Or if there is another solution maybe? Thanks!

I use this code:

$ (function() {
$("#menu > li > a").click(function() {

 //gets the image source
var menyitem = $(this).children("img").attr("src");


// searce and replace "silver" with "blue"
var changedSrc=menyitem.replace("silver", "blue");


// changes the attribute SRC with the new one
$(this).children("img").attr("src", changedSrc);


});
});


$(function() {
    $("#menu > li > a").click(function() {

        // reset all images
        $("#menu > li > a > img").attr("src", function(i, val) {
            return val.replace("blue", "silver");
        });

        //gets the image source
        var menyitem = $(this).children("img").attr("src");


        // searce and replace "silver" with "blue"
        var changedSrc = menyitem.replace("silver", "blue");


        // changes the attribute SRC with the new one
        $(this).children("img").attr("src", changedSrc);


    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜