Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
JavaScript and Ajax

alter css values dynamically with javascript

You can use javascripts document.getElementById().style method to alter CSS values. Here’s an example:

Create your div tag:

Now create your javascript function:

function changeCss()
{
     document.getElementById("myDiv").style.border = '2px dotted #CCC';
}

Now you can call this javascript function on any given event to alter your CSS tags border. Things like height, width, and a bunch others work as well. For instance create an html button, and onclick call the changeCss() function.

No related posts.

Leave a Reply