悬停按钮使用jQuery的? [英] Hovering on buttons using jquery?
问题描述
Doing a hovering event on button as below.
JQuery代码是:
<div id="common_id">
<div class="button" id="make_larger">
<button type="button">Large</button>
</div>
<div class="button" id="make_small">
<button type="button">Smaller</button>
</div>
<div class="button" id="make_normal">
<button type="button">Normal</button>
</div>
</div>
JQuery code is:
Css是:
$('#common_id .button').hover(function () {
$(this).addClass('hover1');
}, function () {
$(this).removeClass('hover1');
});
Css is:
将鼠标放在按钮上时,完整的行到页的末尾)变黑,即使按钮没有变黑,但它的背景在该行看起来是黑色的。
我想让按钮在我悬停时变成黑色。
为什么它不工作?
.hover1 {
background-color:Black;
position:relative;
}
预先感谢。
推荐答案
the div is taking the 100% width. so instead of selecting the div select the button. So your selector should look like this
$('#common_id .button button').hover(function () {
$(this).addClass('hover1');
}, function () {
$(this).removeClass('hover1');
});
试试这个小提琴
这篇关于悬停按钮使用jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!