我有以下风格:
#menu-content p
{
font-family: Verdana, sans-serif;
font-variant: small-caps;
font-size: 2.5vmin;
font-weight: 100;
}
我该如何使用jquery更改字体粗细?对我来说,调用的语法不清楚。会不会是
$("#menu-content p").css ("font-weight", "150");
或
$("#menu-content").$("p").css ("font-weight", "150");
我两个都试过了,似乎都不管用。
发布于 2018-02-13 23:23:37
您需要更改它,以便具有visible effect的内容-那么您的第一个调用是正确的,假设调用时页面中存在被访问的元素:
$(function() { // when page has loaded - you might have missed this
setTimeout(function() { // just for the demo
$("#menu-content p").css ("font-weight", "550");
$("#menu-content p").html("Now font-weight: 550")
},2000);
});
#menu-content p {
font-family: Verdana, sans-serif;
font-variant: small-caps;
font-size: 10vmin 1rem;
font-weight: 100;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Wait 2 secs
<div id="menu-content"><p>Initial font-weight: 100</p></div>
发布于 2018-02-13 23:22:06
您只能更改id,因为它是唯一的:
$("#menu-content").css("font-weight", "150");
https://stackoverflow.com/questions/48770038
复制相似问题