I want to change the color of a title when a button is clicked. This is my code, but it's not working and I can't figure out why not...
<div id="about">About Snakelane</div>
<input type="image" src="http://www.blakechris.com/snakelane/assets/about.png" onclick="init()" id="btn">
and my js...
var about;
function init() {
about = document.getElementById("about").innerHTML;
about.style.color = 'blue';
}
This question is related to
javascript
button
colors
onclick
use ONLY
function init() {
about = document.getElementById("about");
about.style.color = 'blue';
}
.innerHTML()
sets or gets the HTML syntax describing the element's descendants., All you need is an object here.
innerHTML
is a string representing the contents of the element.
You want to modify the element itself. Drop the .innerHTML
part.
<div id="about">About Snakelane</div>
<input type="image" src="http://www.blakechris.com/snakelane/assets/about.png" onclick="init()" id="btn">
<script>
var about;
function init() {
about = document.getElementById("about");
about.style.color = 'blue';
}
Try below code:
$(document).ready(function(){
$('#about').css({'background-color':'black'});
});
Source: Stackoverflow.com