0

How do you change CSS in jQuery? I just want the font color for "Valid VIN" to be red and this does not work:

$("#result").html(<font color="red">"Valid VIN"</font>);
1
  • Can you provide the full HTML? Commented Oct 16, 2014 at 20:45

2 Answers 2

7

You would use the .css() method.

.css() can be used in one of two ways. You can pass two string parameters, a CSS property and a value, or you can pass one object parameter with key (CSS property) and value (CSS value) pairs:

$('#result').css('color', 'red');
// or
$('#result').css({color: 'red'});

If you were targeting the <font> tag inside then:

$('#result font').css('color', 'red');

Note: I should point out that the <font> tag is obsolete, so there's that.

You can also pass a function to set a CSS value:

$('#result').css('color', function(){
   return '#'+(Math.random()*0xFFFFFF<<0).toString(16); //A random colour
});
Sign up to request clarification or add additional context in comments.

1 Comment

It should be noted that the font tag has been deprecated.
1

You must change the attribute value of the font tag

$('#result font').attr('color' , 'red');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.