Home > Enterprise >  Why can't I assign all padding values?
Why can't I assign all padding values?

Time:10-29

I tried to change all paddings of the html element with js, like:

const pd = 1
document.getElementsByClassName('board')[0].style.paddingRight = pd   'px'
document.getElementsByClassName('board')[0].style.paddingLeft = pd   'px'
document.getElementsByClassName('board')[0].style.paddingTop = pd   'px'
document.getElementsByClassName('board')[0].style.paddingBottom = pd   'px'

but it sets the padding to 1px.

If one of the lines is removed eg.:

const pd = 1
document.getElementsByClassName('board')[0].style.paddingRight = pd   'px'
document.getElementsByClassName('board')[0].style.paddingTop = pd   'px'
document.getElementsByClassName('board')[0].style.paddingBottom = pd   'px'

other values are set properly.

Can anyone explain why is this happening, and how can I fix it?

CodePudding user response:

Because I can't comment so i trying to answer

Can you show me your test results and what do you want

There's nothing wrong with your javascript script

If you want to change all the padding why not

 selector.style.padding = "1px"

Or

 Selector.style.padding = "1px 1px 1px 1px"

What is the reason you type that much?

  • Related