tags:

views:

46

answers:

1

Hi,

I have a site where the HTML is just a mess (generated by SharePoint designer).

I need to print the the page, but it looks like crap in IE7/8 print preview, so I need to use <style type="text/css" media="print"> to alter some tables, divs etc, but a lot of the elements have no class or ID. Is there a way to use the print stylesheet and jQuery together to find elements? When I search on Google, most of the links are about switching stylesheets.

Thanks in advance.

+5  A: 

You could use jQuery's powerful selectors to actually ADD classes that you might need, which will then be accessible from your print stylesheet.

For example.

$("p:last-child").addClass("last-para");
$("tr:odd").addClass("odd-row");
$("table:eq(5)").addClass("table6"); // 6th table, starting from a 0 index!

Just for fun, here's some jQuery magic that will add a class (numbered) to all your tables AND all your rows within a table.

$("table").each(function(index, value) {
    $(this).addClass("table" + index);
    $("tr", this).each(function(index, value) {
        $(this).addClass("row" + index);
    });
});

If you need help with specifying particular elements, post them in your question and we'd be happy to help.

Marko
Thanks, I think I will make from here but will get back if I have any further questions.
Peter
you're too fast man, I have to wait 10 min before I can accept an answer :)
Peter
ok, one more question, let's say I for example want to find the 6th table on the page and add a class to that, is that possible?
Peter
Yes it is, see my updated answer :)
Marko
thank you for that!
Peter
Check out my last edit, you can now have all your tables/rows numbered :)
Marko