I am trying to move div
's position but it is not moving. Any idea?
$(document).ready(function()
{
$("#btn1").click(function(){
$("#box").attr("left","300px");
});
});
You can try this
$(document).ready(function()
{
$("#btn1").click(function(){
$("#box").css("position", "relative");
$("#box").css("left","300px");
});
});
</script>
simple answer: $('#box').css({'left': '300px'});
Also make sure your position
is set to either absolute
, relative
or fixed
.
The div
is probably position: static
.
It needs to be one of
position: relative
position: absolute
position: fixed
for left
to have any effect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.