开发者

Using jQuery how can you select all DOM elements that have a pixel value set in the source HTML?

I'm writing some te开发者_开发问答sts 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜