问题描述
这是我的CSS课:
.my-css-class-name
{
display: block;
}
我的网页上有一个使用此类的元素.我想修改此元素的显示"属性.
我会很高兴地通过获取该元素的句柄然后修改所需的内容来做到这一点,但是,我不知道该元素的名称-它是随机生成的(这是第三方扩展名).
And I have one element at my webpage that uses this class. I want to modify this element's "display" property.
I would happily do this by getting a handle to that element and then modifying what I need, BUT, I don't know the element's name - it's being randomly generated (it's a third-party extension).
所以我认为我将必须获取".my-css-class-name"的句柄并直接修改该属性.
跨浏览器(主要的)解决方案,我如何到达那里?
So I figured I'm gonna have to get a handle to ".my-css-class-name" and modify that property directly.
How do I get there, cross-browser (major ones) solution?
编辑#1:
我正在寻找与新型浏览器的兼容性.
Edit #1:
I'm looking for compatibility with newer browsers.
推荐答案
在注释中响应之后,如果元素是由Jquery生成的,则很可能已安装了该库.您可以尝试通过Jquery选择它并更改require属性.
Following your response in the comment, if the element is being generated by Jquery, then the library is most likely installed. Here is something you can try to select it via Jquery and change the require property.
$(document).ready( function(){
$('.my-class-name').css('display', 'block');
});
用"block"代替您需要的任何设置.
Substituting 'block' for whatever setting you require.
如果包含了Jquery,它应该执行您在页面加载时所需的操作.您还可以将其附加到其他事件上.
If Jquery is included it should do what your require on page load. You can also attach it to other events as well.
$(document).ready(function(){
$('.my-class-name').click(classClicked);
})
function classClicked(){
$(this).css('display','block')
}
这篇关于javascript修改css类属性,同时只知道类的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!