+ 2
Changing Style of html element using js,
I used, var x= document.getElementById("element name").style; x.cssproperty=new value; its saying Null , what's the possible cause
5 Respuestas
+ 4
you should say
var x = document.getElementById("elementName");
x.style.color = "red"
this should work for texts
...and remember to wrap it up in
window.onload = function(){
//your code goes here
}
+ 2
put it inside
window.onload = function(){
}
eg:
https://code.sololearn.com/WDz18uXm8N3c/?ref=app
...if the problem persists, you can paste the code here.
+ 1
Here is a simple and pretty cool example 😃
<!---✓ HTML (Hyper Text Markup Language)-->
<div id ="demo">SOLOLEARN</div>
<button onclick ="myFunction()">CHANGE</button>
<script>
// ✓ JS (JavaScript)
function myFunction() {
var x = document.getElementById("demo");
x.style.color = "red";
x.style.backgroundColor = "yellow";
x.style.fontSize = "30px";
}
</script>
😃 KEEP CODING.
0
its saying cannot read Style proper ty
0
am using click event function