jQuery check if font weight is normal or bold

二次信任 提交于 2020-01-03 10:22:36

问题


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?


回答1:


you can get it using:

fontWeight = $(this).css('font-weight')

To compare:

if (fontWeight  == 'normal'|| fontWeight  == '400')
//or
if (fontWeight  == 'bold' || fontWeight  == '700')



回答2:


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
}


来源:https://stackoverflow.com/questions/22323035/jquery-check-if-font-weight-is-normal-or-bold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!