2

I'm writing an extension for chrome as "Content script". My extension should change the background color of google home page (https://www.google.com) I wrote this code (including jquery):

$(".gsib_a").style="background:#FF0000";

But not worked. I'm sure I added jQuery to content script, and the manifest.json file is set. I am sure because this code works:

$(".gsib_a").hide();

And I am sure changing style of the element with class of gsib_a is exactly what I need and affects. Because I've tested it by Chrome Developer Tools.

Okay, who knows the problem?

Mostafa Farzán
  • 899
  • 2
  • 11
  • 30
  • Do you want to change styles only? If yes, why not just inject CSS instead of JavaScript? See [this question](http://stackoverflow.com/questions/9721344/my-css-is-not-getting-injected-through-my-content-script) for sample code. – Rob W Aug 29 '12 at 10:03

1 Answers1

1

if you want to change an attribute, use the attr method: ​ $('.gsib_a').attr('style','background-color:#FF0000')​;

but you can change the css directly with the css method:

​$('.gsib_a').css('background-color','#FF0000')​;
Skalár Wag
  • 2,247
  • 2
  • 18
  • 21
  • Yes, the first code worked. But the second one does not work. However, thank you. – Mostafa Farzán Aug 29 '12 at 09:55
  • the difference: the first code resets the style, the second just changes or sets the background-color. Maybe there is a background-image, which hides the background-color or something like that. – Skalár Wag Aug 29 '12 at 10:03