0

Can I change elem's css rule by input range without js? Like this:

  <input type="range" min="0" max="100">
  <span>Some text</span>


 input[value="0"]+span {background:red;}
 input[value="50"]+span {background:green;}
1
  • Well the first thing I'd try is spelling value correctly. Beyond that this is what I'd try. Commented Sep 15, 2013 at 6:29

1 Answer 1

1

No, the CSS parser would look for an attribute called value with a value of 0. It's a stupid language and isn't meant to interpret the way you're hoping. You could add JS to give the input an actual value attribute with the appropriate value on range change, and then the CSS would pick up on it.

Example jQuery snippet:

$('[type="range"]').on('change', function() {
    $(this).attr('value', this.value);
}).change();

Demo: http://jsfiddle.net/seancannon/FqZZz/

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.