I'm trying to change the margin-top css element of a div using javascript but its not working. Here is my code:
document.getElementById("sidescrollbtn").css({'margin-top':'70px'});
Any ideas?
I'm trying to change the margin-top css element of a div using javascript but its not working. Here is my code:
document.getElementById("sidescrollbtn").css({'margin-top':'70px'});
Any ideas?
In vanilla JS, just set .style.{camelCasedProperty} = 'value';
document.getElementById("sidescrollbtn").style.marginTop = '70px';
You can also do it with jQuery using the object notation you tried:
$('#sidescrollbtn').css({ 'margin-top': '70px' });
You can do it a several ways:
// Reference property name
document.getElementById("sidescrollbtn").style.marginTop = '70px';
OR
// Use setAttribute method
document.getElementById("sidescrollbtn").setAttribute("style", "margin-top: 70px");
OR
// Use jquery .css()
$('#sidescrollbtn').css({ 'margin-top': '70px' });
Additional Information
OR's bold a legitimate edit. If I wanted them bold, I would have made them bold.