I am trying to define a JQuery statement for finding elements which have a greater (or lesser respectively) font-size
than an input value.
Possible input values:
"12px"
"14pt"
"120%"
and so on...
My first approach is more of a draft because it cannot work this way. But maybe you have ideas how to achieve a solution. Here is what i have so far (the input value comes from elsewhere and is variable):
$('*').filter(function() {
return $(this).css('font-size') > '12px';
})
Anyone?
Update
I was asked to explain why i would need something like this. I am writing an API using Selenium2 in Java, which is able to find elements and interact with them in an easier and more reliable way. This function will allow me to write code like browser.find().titleElements()
which selects all h1
, h2
,... tags, but also elements which have a greater font-size than the average text on the page.
The framework will also provide functions to select elements which are visually close to each other or in a specific direction:
HtmlElement nameLabel = browser.find().labelElement("name");
HtmlElement nameInput = browser.find().closestInputElement(nameLabel);
nameInput.below("tos").select();
I made a small plugin that's able to take all the parameters you ask for. No idea how accurate it is since I made it in a rush.
pt
will definately be off if your DPI is anything other than 72.Plugin code
Usage
You can try it out in this test case on jsFiddle.
Additional credits to converter for helping out with the optimization.
You can use parseint so something like this:
and call it like this:
you need to parse the font size...
try this way..