更改来自JS的所有元素的Css [英] Change Css for All elements from JS
问题描述
我试图从一个小显示设置面板更改jQuery对话框的字体系列。
我试过所有这些都无济于事:
$('#orderHolder')。style.fontFamily ='Bookman Old Style';
$('。ui-dialog-content')。style.fontFamily ='Bookman Old Style';
$('。ui-widget-content')。style.fontFamily ='Bookman Old Style';
$('#orderHolder').css(font-family,Bookman Old Style';
$('*').css('font-family','Bookman Old Style' ); //这是我在
之后的内容
(#orderHolder是包含对话框的div内容)
我发现
* {
font-family:'Bookman Old Style';
}
在.css文件中工作正常,整体效果就是我所追求的。
所以,你如何在javascript中选择所有的样式元素?
我发现
* {
font-family:'Bookman Old Style '。
}
在.css文件中工作正常,整体效果是
在这种情况下,由于您显然未应用 font-family
更具体的选择器,你最好的选择是添加样式$ c $使用该规则:
$(< style> * {font-family:'Bookman Old样式';可能:)。appendTo(head);
p>
$(< style> body {font-family:'Bookman Old Style';}< / style>)。 appendTo(head);
...如果它们都从<$ c $继承它们的样式c> body 。
通过这种方式,它可以贯穿始终,也适用于之后添加的新元素。
I'm trying to change jQuery dialog's font-family from a little display settings panel. I've tried all of these to no avail:
$('#orderHolder').style.fontFamily='Bookman Old Style';
$('.ui-dialog-content').style.fontFamily='Bookman Old Style';
$('.ui-widget-content').style.fontFamily='Bookman Old Style';
$('#orderHolder').css("font-family", "Bookman Old Style';
$('*').css('font-family', 'Bookman Old Style'); //this is what I'm after
(#orderHolder being the div that contains the dialog content)
I found
*{
font-family: 'Bookman Old Style';
}
in the .css file works fine, and the overall effect is what I am after.
So, How do you select all elements for styling in javascript?
I found
*{ font-family: 'Bookman Old Style'; }
in the .css file works fine, and the overall effect is what I am after.
In that case, since you apparently aren't applying font-family
to more specific selectors, your best bet is to add a style
element to the document with that rule:
$("<style>* { font-family: 'Bookman Old Style'; }</style>").appendTo("head");
Or possibly:
$("<style>body { font-family: 'Bookman Old Style'; }</style>").appendTo("head");
...if they all inherit their style from body
.
That way, it applies throughout, and also to new elements you add afterward.
这篇关于更改来自JS的所有元素的Css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!