Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created May 26, 2012 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/2791873 to your computer and use it in GitHub Desktop.
Save kazu69/2791873 to your computer and use it in GitHub Desktop.
data binding attributes
<!--
http://ericbidelman.tumblr.com/post/23615290220/data-binding-using-data-attributes
-->
<style>
input[type="range"] {
vertical-align: middle;
margin: 2em;
font-size: 14px;
height: 20px;
}
input[type="range"]::after {
content: attr(data-value) '/' attr(max);
position: relative;
left: 135px;
top: -20px;
}
</style>
</head>
<body>
<input type="range" min="0" max="100" value="25">
<script>
var input = document.querySelector('input');
input.dataset.value = input.value;
input.addEventListener('change', function(e) {
this.dataset.value = this.valueAsNumber;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment