简体   繁体   中英

Using javascript to manipulate css elements, dash margin-left

I'm trying to use this

document.getElementById('menu2').style.marginleft = "5%";

To manipulate the margin-left: 20%; to become margin-left: 5%;

I don't know what to do with the dash, if it's a single word like style.width, it's no problem, but a dash seems problematic, what do I do?

请改用marginLeft ,并使用marginLeft “ L”。

can use this

$('#menu2').css({"marginLeft":"5%"});

Fiddle Here

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM