tags:

views:

95

answers:

7

My html page includes tons of text including lots of DIVs and Tables.

At the end of the code, there's an automatically created code such as:

<div id="fld1_date" ... style="position:absolute;visibility:hidden">

</div>
<div id="fld3_date" ... style="position:absolute;visibility:hidden">

</div>
<div id="fld8_date" ... style="position:absolute;visibility:hidden">

</div>

The DIVs don't have a "class" attribute.

The problem is that these DIVs create EMPTY LINES AT THE END OF THE PAGE. Which cause the horizontal scroll to appear, and printing of the page to take more than 1 page.

The Ids are assigned randomly and I can not work with them. In fact, I can not touch these lines in any way but have to build some sort of work around through the CSS.

Of course I can not override the default DIV behavior in the CSS because it screws up all the other divs (and there are dozens of them).

Any ideas how I can handle it? (I know that the design isn't perfect, this is a 5000 programmer hours system and changing it will be a problem)

+1  A: 

Is there an outer container for the divs?

With javascript and Mootools, I would've done something like this if that was the case;

$('outerContainer').getElements('div').setStyle('display', 'none');
Björn
I wish there was....
Faruz
+1  A: 

Change

visibility: hidden

to

display: none

and it won't take up any additional space

rahul
"The Ids are assigned randomly and I can not work with them. In fact, I can not touch these lines in any way but have to build some sort of work around through the CSS."
Faruz
A: 

If you can; you should wrap these created divs in a parent div that you should create and hide that; here is how:

<div id="mydiv">
 <div id="fld1_date" ... style="position:absolute;visibility:hidden">

 </div>
 <div id="fld3_date" ... style="position:absolute;visibility:hidden">

 </div>
 <div id="fld8_date" ... style="position:absolute;visibility:hidden">

 </div>
</div>

Now apply following css to hide all:

<script type="text/css">
div#mydiv
{
 display:none;
}
</script>
Sarfraz
no I can not. It's automatically created...
Faruz
A: 

Are you able to wrap the automated content in a div you can identify and control?

DanDan
No I can not, it's automatically created
Faruz
Do you have any kind of reference elements you could use? Since they're are sequential, I assume they have at least a fixed predecessor or something like that. Is that the case?
danielkza
Sort of. There's a div called "divToolbar". After it there's a random number of <script> tags. And afterwards come the DIVs. FYI: after the divs is some AjaxControlToolkit code and then </body>
Faruz
+4  A: 

Here are some ideas:

  • Use the body > div child selector to assign display:none to all DIVs directly underneath the body tag, and manually fix the "collateral damage". Depending on the structure of your document, this might leave a lot less DIVs to be explicitly display:blocked afterwards. The > selector does not work on IE6, though.
  • Use JavaScript to iterate over all DIVs, identifying the offenders and setting their display value to none. This requires that you can add any JavaScript at all, of course, and also that there's some criterion you can use to identify the DIVs (need not be the ID, maybe they're always the last DIVs on the page, always come after some end-of-page markup or somesuch)
  • Use conditional CSS formats à la div[id|=fld] to catch all DIVs with an ID starting with "fld". I'm not sure if this violates "I can not work with them" concerning the IDs, though, and it's also not working on IE6 (and probably newer, the docs I have are too old to know). You can of course use any attribute in the DIVs, not just id (style, perhaps?)

edit: added link

Simon
Love the idea behind the third bullet.Could you elaborate and maybe add a link to some sort of an example?
Faruz
The third idea is the most fitting but it wont work in IE < 6. I'd just take the hit since IE6 should be completely deprecated anyways and go with that. +1
cballou
div[id|="fld"] { display: none; } should do the trick and seems to work in IE7 and up - see http://www.w3.org/TR/CSS21/selector.html#attribute-selectors and http://msdn.microsoft.com/en-us/library/cc351024%28VS.85%29.aspx#attributeselectors
Olly Hodgson
Olly already linked the attribute selectors for #3, I just added the child selectors link for #1. Boldewyn posted JavaScript code for #2.
Simon
+1  A: 

In addition to Simon's suggestions: If the problematic divs are the only ones with 'visibility:hidden' set explicitly, you could do this:

var divs = document.getElementsByTagName("div");
for(var i = 0; i < divs.length; i++) {
  if (divs[i].style.visibility == "hidden") {
    divs[i].parentNode.removeChild(divs[i]);
  }
}

which effectively removes the element completely from the DOM (might have a better performance than styling each with "display:none").

Boldewyn
I need to work hard to add Javascript here.. the best solution will be entirely css-based.
Faruz
+1  A: 

If the div's are appended directly to body and they all have the same ID pattern, then you can do iterate over div's at this level and hide those that match the pattern:

$("body > div").each(function(i, d) {
    if ( d.id && /fld\d+_date/.test(d.id) ) {
        $(d).hide();
    }
});

If the generated ID's will always be in that pattern ("fld1_date") and there will never be another similar pattern (e.g.: "fld_foo_date"), then you can probably get away with something like:

$("body > div[id^=fld][id$=_date]").hide();

See the jQuery selector doc for more information.

* All of my code is untested.

Justin Johnson