tags:

views:

50

answers:

5

I would like to have jQuery append a style="text-align: left;" to all elements on my page.

I know I would probably have to do something like:

$('everything-in-the-page').each( ...

But I'm a little confused as to how I can select every HTML tag.

JUST TO STOP THE BACKLASH: This is for an accessible site (print only). So, YES I KNOW it's bad practise.

+1  A: 

What about using * as CSS selector, if you want to indicate everything ?

i.e. :

$('*').each(...


As a reference, you can take a look at 5.3 Universal selector (quoting) :

The universal selector, written "*", matches the name of any element type. It matches any single element in the document tree.

Pascal MARTIN
You should note this is a **really** bad idea...
Nick Craver
@Nick : yes, probably -- didn't think to say it, so, thanks for the comment :-)
Pascal MARTIN
+5  A: 

If you need to do this (please don't, it's a really bad idea for a few reasons, performance for starters):

$('*').css('text-align', 'left');

But it seems like just a single CSS rule would do the job:

body { text-align: left; }
Nick Craver
A: 
$('*').each(...
Darin Dimitrov
+2  A: 

What about:

$('*').css('textAlign', 'left');
Ardman
Works for me...
Neurofluxation
Since this was accepted - to save future googlers.... **Styles cascade** (CSS, *cascading* style sheets), applying it *once* to the `<body>` in CSS will do the job, not sure what the focus on making this perform as slow as possible is. `text-align` on a parent goes (cascades) to the child, `$('body').css('text-align', 'left');` would be all you needed to do this, if you have specific elements that have another `text-align` property applied, select those, but selecting everything is *rarely*, if **ever**, a good idea.
Nick Craver
A: 

If you want a print-only style, you can still use CSS:

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

JavaScript isn't a good way to achieve better accessibility - your will better work well even with JavaScript disabled.

More details: A List Apart - CSS Design: Going to Print

Kobi