w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
highlight and un-highlight item selected in jquery

Following the method you are already doing:

$( ".imgStyle img").bind( "click", function() {
    $( ".imgStyle img").removeAttr("style");
    $(item1).css("border", "5px solid grey");
}

Since the jquery's .css() method adds the property to the inline style attribute of the element, removing this style of everyother img should be enough

BUT

You'd better use a class to define a selected element, like:

.selected {
    border: 5px solid gray;
}

And then:

$(".imgStyle img").bind("click", function() {
    $(".selected").removeClass("selected");
    $(this).addClass("selected");
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.