[英]Why the css font-weight property is not working in my case?
My selected_cell just contains a paragraph as its child with a default normal class applied.我的 selected_cell 只包含一个段落作为其子级,并应用了默认的普通类。
My css code:我的CSS代码:
.normal{
font-weight: normal;
}.bold{
font-weight: bolder;
}
My JS Code:我的JS代码:
function bold()
{
var selectedcell=document.querySelector('.selected-cell');
if(selectedcell.children[0].class=="normal")
{
selectedcell.children[0].class="bold";console.log(selectedcell.children[0])}
else
{
selectedcell.children[0].class="normal";console.log(selectedcell.children[0])};
}
Here I have created a function bold wherein I make the text of the selected cell look bolder using the font-weight property.But apparently it doesnt work.在这里,我创建了一个粗体函数,其中我使用 font-weight 属性使所选单元格的文本看起来更粗。但显然它不起作用。
Try this尝试这个
function bold()
{
let selectedcell = document.querySelector('.selected-cell');
if(selectedcell.children[0].classList.contains("normal"))
{
selectedcell.children[0].classList.replace("normal","bold");
}
else
{
selectedcell.children[0].classList.add("normal");
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.