开发者

Change className on keydown

I want to do so that when I press the button A the class of the element gets 开发者_JS百科the same "class" as it gets on mouse over. (in CSS i have kay:hover to change the style ).

But I need to change the key to key:hover for specified classname. Like onkeydown change style from "key C" to "key:hover C" :/

How do i achieve this effect?

Sorry if i explained badly :P


You can do something like

$('#area').keydown(function(event) {
    if (event.keyCode == '65') {
        $('#elementToChange').attr('class', 'newClass');
    }
});

Where 65 is the keycode for the letter 'a'

Then add

$('#area').keyup(function(event) {
    if (event.keyCode == '65') {
        $('#elementToChange').attr('class', 'oldClass');
    }
});

to set the class back to what it was when you release the 'a' button.


SOLVED i just did

KEYDOWN: document.getElementById("keyC").className = "key2 C"; KEYUP: document.getElementById("keyC").className = "key C";

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜