To clear things up a little, since some of the answers are providing incorrect information:
The jQuery .css() method allows the use of either DOM or CSS notation in many cases. So, both backgroundColor
and background-color
will get the job done.
Additionally, when you call .css()
with arguments you have two choices as to what the arguments can be. They can either be 2 comma separated strings representing a css property and its value, or it can be a Javascript object containing one or more key value pairs of CSS properties and values.
In conclusion the only thing wrong with your code is a missing }
. The line should read:
$("#myParagraph").css({"backgroundColor":"black","color":"white"});
You cannot leave the curly brackets out, but you may leave the quotes out from around backgroundColor
and color
. If you use background-color
you must put quotes around it because of the hyphen.
In general, it's a good habit to quote your Javascript objects, since problems can arise if you do not quote an existing keyword.
A final note is that about the jQuery .ready() method
$(handler);
is synonymous with:
$(document).ready(handler);
as well as with a third not recommended form.
This means that $(init)
is completely correct, since init
is the handler in that instance. So, init
will be fired when the DOM is constructed.