user24984 user24984 - 2 years ago 60
Javascript Question

jQuery .css is not setting the attribute

In the following code snippet, when the css attribute is set, the text color does not change. The color of the text should be red when the button is clicked.

$('#changeColor').on('click', function(){
$('#test').css('color', 'red;');

<script src=""></script>
<div id="test">
This text should turn red when the button is clicked
<button id="changeColor">Change test color to red</button>

Answer Source

The semicolon is preventing setting this attribute. Change it to:

$('#test').css('color', 'red');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download