user24984 user24984 - 1 year ago 36
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>


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

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