0

How is it possible to control CSS with a range slider via jQuery?

Some example code:

$('.font_size').on('input', function() {
  var fontsizeval = $(this).attr('value');
  var fontsizemin = $(this).attr('min');
  var fontsizemax = $(this).attr('max');
  $('.text').css("font-size", fontsizeval + "px");
});
* {
  font-size: 12px;
}

.text {
  font-size: 120px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="text">Text
  <div>

    Font Size: <input class="font_size" type="range" value="120" min="30" max="200">

Would be very thankful for help!

1 Answer 1

1

use val() instead of attr("value")

$('.font_size').on('input', function() {
  var fontsizeval = $(this).val();
  var fontsizemin = $(this).attr('min');
  var fontsizemax = $(this).attr('max');
  $('.text').css("font-size", fontsizeval + "px");
});
* {
  font-size: 12px;
}

.text {
  font-size: 120px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  Font Size: <input class="font_size" type="range" value="120" min="30" max="200">
<div class="text">Text
  <div>

  

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.