I'm setting the font-weight property with the following code:
$(this).css({ 'font-weight': 'normal' });
Now i want to check if an element has bold or normal font-weight propety, how do i do this?
Highlight the text and click on the link. document. queryCommandState("bold"); //That's the command I've been searching.
The CSS spec specifies that font-weight and font-size are inherited. This simply means that any element with no alternative rule for those properties will cause them to inherit the final, computed values from their parent.
normal: This is the default font-weight & defines the normal font-weight. It is equal to the number value 400. bold: This defines the bold font-weight, it is equal to the number value 700.
The font-weight property can separately be used to set how thick or thin characters in text should be displayed.
you can get it using:
fontWeight = $(this).css('font-weight')
To compare:
if (fontWeight == 'normal'|| fontWeight == '400')
//or
if (fontWeight == 'bold' || fontWeight == '700')
You can use:
if ($('#yourElement').css('font-weight') == 'normal') {
// Your code if font-weight is normal
} else if($('#yourElement').css('font-weight') == 'bold') {
// Your code if font-weight is bold
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With