我有以下小jQuery hack使<strong>Warning</strong>
中显示的任何HTML显得大而红:
$("strong:contains('Warning')").css("color","red").css("font-size","400%");
它很漂亮。但是,它使所有大而红,并且我真的只希望它使警告大而红,如果它们也出现在标识为myWarning
的范围内。例如:
<span id="myWarning">
<div align="left" class="tip">
<strong>Warning</strong> (I want this to be big and red...)
</div>
</span>
<strong>Warning</strong> (...but I don't want this to be big and red)
如何增强我的jQuery hack以使其仅修改第一个“警告”的CSS而不是第二个?
答案 0 :(得分:1)
只需将#myWarning
添加到您的选择器中吗?
$("#myWarning strong:contains('Warning')").css("color","red").css("font-size","400%");
答案 1 :(得分:0)
$("#myWarning strong").css("color":"red", "font-size":"400%");
答案 2 :(得分:0)
我想你想要的第一个这样的警告要大而红?
$("strong:contains('Warning')").first().css("color","red").css("font-size","400%");
答案 3 :(得分:0)
为什么要使用jQuery?为什么不简单地使用CSS:
#myWarning strong { color: red; font-size: 400%; }