我的html里有个按钮。点击它,我想在按钮前插入一个绿色的方框("div")。在jquery中有什么方法可以做到这一点吗?我写了下面的代码,但它不工作。新元素出现在我的按钮上。
click: function () {
var oldLeft = parseInt($('#addButton').css('left'));
var newFU = $('<div class="fu"></div>');
newFU.insertBefore("#addButton");
var newLeft= oldLeft + newFU.width();
$("#addButton").css("left", newLeft);
$(this).dialog("close");
}相关css如下所示:
div .fu {
width: 50px;
height: 50px;
background-color: #19833F;
position: absolute;
color: white;
text-align: center;
vertical-align: middle;
}
.addButton{
font-weight: bolder;
background-color: white;
color: #20ff5c;
font-size: 18px;
left: 20px;
}发布于 2014-10-07 17:04:59
我通过定义具有相对位置的按钮解决了这个问题:
。
addButton{
font-weight: bolder;
background-color: white;
color: #20ff5c;
font-size: 18px;
left: 10px;
position: relative;
}https://stackoverflow.com/questions/26232198
复制相似问题