noahbald
noahbald

Reputation: 75

How to prevent JavaScript from filling in unspecified parts of style

If I set the style of an element with JS it seems to fill out the parts of the style which I intentionally left unspecified.

For example, if I set the transition style

el.style.transition = 'width .2s'

The html changes to

<div style="width: 50px; transition: width 0.2s ease 0s;"></div>

Which is inconvenient, because I want to be able to set the timing function in css without using !important

Does anyone know any simple ways to get around this, ideally without manipulating el.attributes.style?

Upvotes: 0

Views: 46

Answers (1)

Ikdemm
Ikdemm

Reputation: 2353

That has nothing to do with JavaScript. That's the default behaviour of transition. You could, for instance, try and make it the way you want by either specifying the duration yourself or by using el.style.transitionDuration

el.style.transitionDuration = "1s";

Upvotes: 1

Related Questions