简体   繁体   English

将CSS应用于动态命名的元素

[英]Applying CSS to dynamically named elements

I wrote a theme for Google+. 我为Google+写了一个主题。 It injects CSS/Javascript to replace some colors, background images, etc. They recently seem to have renamed a lot (most) of their classes and ID's. 它注入CSS / Javascript来替换一些颜色,背景图像等。他们最近似乎已经重命名了很多(大多数)他们的类和ID。 If I were to rewrite the code, is there a way to assign CSS (through javascript, presumably, like jquery's .css() function) to page elements with dynamic names? 如果我要重写代码,有没有办法将CSS(通过javascript,大概就像jquery的.css()函数)分配给具有动态名称的页面元素?

EDIT: If so, how? 编辑:如果是这样,怎么样?

Code: https://github.com/bichiliad/G-Theme 代码: https//github.com/bichiliad/G-Theme

Example: I used this to replace the logo: 示例:我用它来替换徽标:

$(".aU-Pg-T img:first").attr('src', logoURL); $(“。aU-Pg-T img:first”)。attr('src',logoURL);

However, with the new update, the div enclosing the logo is now ".a-fa-bh-T". 但是,随着新的更新,包含徽标的div现在是“.a-fa-bh-T”。

You could use jQuery find() and regex patterns to try to find the elements themselves based on their hierarchy, but if the hierarchy changes then that won't work either. 你可以使用jQuery find()和regex模式来尝试根据它们的层次结构自己找到元素,但是如果层次结构发生了变化,那么它也无法工作。 And yes, you could use jQuery's css() to apply those styles. 是的,您可以使用jQuery的css()来应用这些样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM