Youss
Youss

Reputation: 4212

Getting rid of background properties

I'm scraping this news website: http://www.nu.nl/

If you open console and type:

$('*').css('background', 'none');

You will see all the background properties being removed, except for one which is the "blue" squire in the first article. When I trace the original CSS I see it has the !important declaration assigned to it. I don't know whether this is causing its persistence. What can I try to get rid of that blue background in terms of Jquery and Javascript or CSS?

Please note I don't want to target the element itself but rather keep using the all (*) selector or some Javascript equivalent.

Upvotes: 1

Views: 110

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50787

jQuery doesn't recognize the !important attribute in css definitions. You just need a more specific hierarchical selector here. Simply make a new class, and then use addClass.

$('head').append('<style type="text/css">html #page .noBG{ background:none !important; }</style>');

Then just add that class to everything.

$('*').addClass('noBG');

Edit

Based on comments below, you could try

$('head').append('<style type="text/css">html body#noBG *{ background:none !important; }</style>');

Then add the ID to the body

$('body').prop('id', 'noBG');

Which is a pretty specific selector. Some rules may still pass this, and you'll have to experiment with different variations depending on the scenario.

Upvotes: 1

Related Questions