且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jquery按键更改CSS

更新时间:2022-10-21 22:17:01

document )。ready( function (){


tr)。hover( function (){


this )。css( background-color red);
}, function (){


Hello,


Why is this working just fine:

jQuery(document).bind('keydown', function (evt) {
        if (evt.keyCode == 38) {
            var element = document.getElementById("table_row_2");
            element.style.backgroundColor = "red";
        }
    });


But this isn't working:

jQuery(document).bind('keydown', function (evt) {
        if (evt.keyCode == 38) {
            var element = document.getElementById("table_row_2");
            element.css("background-color","red");
        }
    });



What I have tried:

while this again works just fine:

<pre lang="text">$(document).ready(function () {
        $("tr").hover(function () {
            $(this).css("background-color", "red");
        }, function () {
            $(this).css("background-color", "red");
        });
    });



Im confused...

(document).ready(function () {


("tr").hover(function () {


(this).css("background-color", "red"); }, function () {