Ad
Passing "value" From Slider To An Element, As An Parameter Of An Attribute
I'm trying to capture an HTML
slider
value
, which is suppose to set a parameter of an attribute (inside a CSS
class).
So, i have a slider
and a div
element - to which i want to pass a value to:
<input type="range" min="1" max="11" value="6" class="slider" id="slider">
<div id="container">
<div id="fg2">text</div>
</div>
In JS I've set those two elements as variables, and added Event Listener
to the slider
, with a function that captures value
from the slider
:
const slider = document.getElementById("slider")
const FGElement = document.getElementById("fg2");
slider.addEventListener("input", function(){
changeSize();
});
function changeSize() {
let i = slider.valueAsNumber;
console.log(i);
}
Now, i want to add a class to FGElement
, inside of which i would put flex-grow: [i]
. Which is my idea to how dynamically capture value
from slider
to FGElement
.
Is it the right way to do it, if so - how to set an parameter of an CSS
class
attribute
in JS?
If not, what would be the correct way...
Ad
Answer
You can't dynamically change values of .css
file
You have to Use JS for to apply inline style
document.getElementById('myElement').style.flexGrow = i;
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad