views:

10

answers:

1

Hi,

I'm writing some tests and one of the assertions has to ensure an HTML document only uses px units of measurement where specified. I'm using jQuery but I can't work out the way to select those elements. These elements will be the ones with things like margin and padding specifically set and not just the inherited values or pixel values converted from em etc.

Cheers

A: 

I'm not sure exactly what you're dealing with, but if these elements have the pixel values set in the "style" attribute, you could use something like

$([style*='px']);

For all of the elements with a style attribute which contains the letters "px". Otherwise, if they are explicitly set in the "width", "padding", and "margin" attributes, it would be something like

$([padding*='px']);

You can read more about the "contains" selector in the jQuery API here:

http://api.jquery.com/attribute-contains-selector/

If this doesn't answer your question, you'll have to be a little more clear about the structure of your document, and perhaps provide some example code.

Melbi
It's actually $("[style*='px']"); but thank you, it works :)
Robin Elvin
Glad it worked. I feel a little silly forgetting the quotes.
Melbi