Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:26:18+00:00 2026-05-22T15:26:18+00:00

I am trying to define a JQuery statement for finding elements which have a

  • 0

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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:26:19+00:00Added an answer on May 22, 2026 at 3:26 pm

    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

    (function($){
        $.fn.filterByFontSize = function(size){
            // Local scope vars
            var relative = false,
                matches = size
                    .toString()
                    .match(/^\d+(?:\.\d+)?(pt|em|%)$/i);
    
            // Parse size
            size = parseFloat(size, 10);
    
            // Check matches
            if (matches !== null) {
                switch (matches[1]) { 
                    case "pt":
                        size = size*96/72;
                    break;
                    case "em":
                        relative = true;
                    break;
                    case "%":
                        relative = true;
                        size = (size/100)+0.01;
                    break;
                }
            }
    
            // Filter elements accordingly
            return this.filter(function(){
                var $this = $(this),
                    thisSize = parseInt(
                        $this.css("font-size"), 10);
                if (relative) {
                    var parent = $this.parent();
                    if (parent[0] === document) {
                        parent =  $(document.body);
                    }
                    var parentSize = parseInt(
                            parent.css("font-size"), 10);
                    return parentSize*size < thisSize;
                } else {
                    return thisSize > size;
                }
            });
    
        };
    })(jQuery);
    

    Usage

    var bigTextElements = $("h1,h2,h3,p").filterByFontSize("24px");
    

    You can try it out in this test case on jsFiddle.

    Additional credits to converter for helping out with the optimization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After the changes made in jQuery 1.6.1, I have been trying to define the
I'm trying to define some default behaviours for my jQuery Dialogs like the following:
I'm trying to define a way in which I can control the access to
I'm trying to run a webmethod via a jQuery which will query an SQL
I am trying to experiment with the jquery template plugin. I have a single
I have a jQuery search script that uses tabs for the user to define
Im trying to define a dataTemplate for a business object in my wpf application
I'm trying to define a task that emits (using echo) a message when a
I'm trying to define a table to store student grades for a online report
I am trying to define a WCF contract that returns an interface, something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.