jquery addclass

You can use the jquery addclass method to add a class name to specified element(s). In this example the div with id 'mydiv' has the class 'green' added to it. The 'green' css class is also specified so the effect is to turn the text within the div green.

Some Text

Code


<div id="mydiv">
<p>Some Text</p>
</div>

<button type="button" onclick="gofunc()" >Go!</button>
<script>
function gofunc()
{
$("#mydiv").addClass("green");
}
</script>

<style>
.green{color:green}
</style>