Get margin top with JavaScript

前端 未结 2 2034
野性不改
野性不改 2021-01-14 00:45

I need to get margin-top of an input with JavaScript. This is the jQuery code which works fine:

alert($(\"#input\").css(\'margin-to         


        
2条回答
  •  天命终不由人
    2021-01-14 01:19

    I just found a solution:

    var style = window.getComputedStyle(document.getElementById('input'));
    var marginTop = style.getPropertyValue('margin-top'); 
    alert(marginTop);
    

提交回复
热议问题