I am following a JavaScript course and I was wondering why this code is not working:
document.querySelector('.message').style.width ='30rem';
document.querySelector('.message').style.transition='0.3s';
This method works if I select HTML elements but does not work with classes. To fix the problem I thought it’d be useful if I edited the element’s properties by adding the style property directly into the element like this:
<div class=".message" style="width=30rem; transition=0.3s;" > </div>
2
Answers
Instead of setting each style property individually, combine them into one string and then apply them using the
cssText
property.