<form> <input type="text" name="text" /> <input type="button" id="btn1" name="btn" value="ボタン" onclick="testFunc(this.id,this.value,this.form.text.value)" /> </form> <script> function testFunc(a,b,c){ console.log(a); console.log(b); console.log(c); } </script>
const target1 = document.querySelector('#example-id'); const target2 = document.querySelectorAll('.example-class'); target1.style.setProperty('color', '#00f'); target1.style.setProperty('position', 'relative'); target1.style.setProperty('top', '3px'); target2.forEach(function (element) { element.style.setProperty('color', '#f00'); element.style.setProperty('font-weight', 'bold', 'important'); });
CSS
:root { --main-size: 256px; } .hoge { width: var(--main-size); }
JavaScript
document.documentElement.style.setProperty('--main-size', '96px');