设置font-weight的jQuery属性

我正在尝试更改元素的字体粗细。 我尝试了以下但它似乎不起作用:

$("#opt_" + i).attr("font-weight", "bold"); 

prop和attr有什么区别? 这与我的问题有关吗?

使用.css()函数代替.attr()

 $("#opt_" + i).css("font-weight", "bold") 

它不是属性,而是CSS:

 $("#opt_" + i).css("font-weight", "bold"); 

例如: http : //jsfiddle.net/niklasvh/ENwbn/

 $("#opt_" + i).style("font-weight", "bold"); 

prop和attr有什么区别?

根据相关说明 .prop()应该用于dom-properties,而.attr()应该用于html属性:

首先,在窗口或文档上使用.attr()方法在jQuery 1.6中不起作用,因为窗口和文档不能具有属性。 它们包含应使用.prop()或仅使用原始javascript操作的属性(例如location或readyState)。 在jQuery 1.6.1中,.attr()将遵循窗口和文档的.prop()方法而不是抛出错误。