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>);
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>);
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
});
font tag has been deprecated.