0

I am trying to add class using JQuery to a button when it is clicked. The following codes show my class and JQuery onclick event with its handler:

CSS

.input-highlight {
     background-color: #1E90FF;
     color: white;
}

JS

$("#elv-geo").on("click", hightlight);

function hightlight() {

    var georgian = $("#geo-elv");

    georgian.addClass("input-highlight");

}

When I had "visibility: hidden" in the class, it did work, but with the above code, it doesn't. Any ideas why?

4

2 回答 2

1

你用过一次 $("#geo-elv")又一次$("#elv-geo")。这可能会导致您的问题..

此外,您应该考虑使用以下语法:

$("#geo-elv").on('click',function(){
    $(this).addClass('input-highlight');
})
于 2013-06-27T11:33:48.263 回答
0
.input-highlight {
    background-color: #1E90FF;
    color: white;
}

var id = "#elv-geo"; // is it elv-geo or geo-elv?
$(id).on("click", highlight);

function highlight() {
    $(id).addClass("input-highlight");
}
于 2013-06-27T11:35:13.723 回答