开发者

help removing extra body tags using jquery

I have an application which is spitting out: body {background: #FFF;}

over and over again. I am unable to fix the bug in the application. How can I use jquery to开发者_如何学运维 remove body {background: #FFF;} each time it occurs?


You can't edit the css (I assume) but can you set an inline style on the body? This will overwrite the CSS applied style.

If not, here is the jQuery call to remove it on page load:

$(document).load(
    function()
    {
        $("body").css( "background-color", "transparent" );
    }
);


It sounds like you're wanting to edit an style block declaration? I'm not sure jQuery really does much to help you in that case, but something like this might work:

for(int i=0;i<document.styleSheets.length;i++) {
  var sheet = document.styleSheets[i],
      rules = sheet.cssRules ? sheet.cssRules : sheet.rules;
  for(int j=0;j<rules.length;j++) {
    if(rules[j].toLower() == 'body {background: #fff;}')
      rules[j] = 'body {}';
  }
}

You might check here for more.


there are multiple instances of this on the page that are overwriting anything I put in the css.

Perhaps you are looking at it the wrong way... It can be overridden in the CSS, try putting this in the CSS file:

body{
   background:#0000ff !important;
}

Note the "!important" bit...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜