I am trying to change the CSS of one element on click of another element. I\'ve searched a lot but nothing works perfectly. Currently I am using the below code, but it doesn
This code seems to work fine (see this jsfiddle). Is your javascript defined before your body?
When the browser reads onclick="myFunction()"
it has to know what myFunction
is.
In your code you aren't using jquery, so, if you want to use it, yo need something like...
$('#foo').css({'background-color' : 'red', 'color' : 'white', 'font-size' : '44px'});
http://api.jquery.com/css/
Other way, if you are not using jquery, you need to do ...
document.getElementById('foo').style = 'background-color: red; color: white; font-size: 44px';