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

My Blog

Here is my awesome blog.

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.

Leave a Reply