简体   繁体   中英

JS add in-line css to html

I'm stuck with something here:

I have a hidden div with some optional filters in a results page.

<div id='b-filters' class='row'>...</div>

Initially it is hidden with display: none; , when click a link it shows with some buttons and selectize combos.

The problem is here:

When div shows up, some JS, I don't know how to find out which; adds some in-line css:

<div id='b-filters' class='row' style='overflow: hidden; display: block;'>...</div>

So it is no possible to see the combos options. Using Chrome debugger I change overflow: hidden to overflow: visible and it works as I'd like.

I have tried:

In my external css file (app.css)

#b-filters{
  ...
  overflow: visible;
  ...
}

But does not work, and in the same html file:

<head>
...
  <style>
    div#b-filters{
      overflow: visible;
    }
  </style>
</head>
...

But Chrome inspector always show overflow: visible; crossed out.

Any idea? Thanks.

EDIT

I took @Stephen Thomas answer, but I'd like somebody help me with the way to find out which JS is adding that in-line css.

Without seeing the actual JavaScript, the only suggestion I can offer is

div#b-filters{
  overflow: visible !important;
}

But if you show us your code, there is probably a more elegant way.

Instead of adding inline CSS directly to the element, why not abstract the CSS attributes into generalized classes, then just add/remove those classes?!

// style.css
.hide {
   display: none;
}

// view.html
<div id="b-filters" class="row hide">...</div>

// app.js
btn.addEventListener('click', function(event){
   var el = document.querySelector('#b-filters');
   el.classList.remove('hide');
});
var problematicDiv = document.getElementById('b-filters');

if(problematicDiv.hasAttribute('style'))
{
    problematicDiv.removeAttribute('style');
    problematicDiv.style.display = 'block';
    problematicDiv.style.overflow = 'visible';
}

This 'pseudo' js code should work as eventlistener.. haven't tested though, but I think it's ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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