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

  • SEARCH
  • Home
  • 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 6552255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:26:15+00:00 2026-05-25T12:26:15+00:00

How do I go on about selecting elements which has the same attribute values

  • 0

How do I go on about selecting elements which has the same attribute values in jquery. And then comparing which of those 2 has a greater value.
Here is what I have so far. The problem that I’m having with this is that I don’t really get any output if the first number in the pair is the larger one.

    <script>
    $(function(){
        var j = [];
        $('.loo').each(function(index){
            var grp = $(this).attr('data-x');
            var num = $(this).val();
            var id = $(this).attr('id');

            var pair_val = pair_value(grp);
            var pair_id = pair_identity(id);

            console.log(get_max(num, pair_val, id, pair_id));
        });

        function get_max(num1, num2, id1, id2){
            var decide = 0;
            if(num1 > num2){
                decide = id1;
            }else{
                decide = id2;
            }
            return decide;
        }

        function pair_value(conn){
            var pair = $("input[data-x="+ conn +"]").val(); //my problem is here
            return pair;
        }

        function pair_identity(conn){
            var pair_id = $("input[data-x="+ conn +"]").attr('id'); //my problem is here
            return pair_id;
        }


    });
    </script>

Html:

    <p>
    <input type="text" id="e" name="e" class="loo" value="1" data-x="a">
    </p>
    <p>
    <input type="text" id="f" name="f" class="loo" value="10" data-x="a">
    </p>
    <p>
    <input type="text" id="g" name="g" class="loo" value="37" data-x="b">
    </p>
    <p>
    <input type="text" id="h" name="h" class="loo" value="25" data-x="b">
    </p>
    <p>
    <input type="text" id="i" name="i" class="loo" value="11" data-x="c">
    </p>
    <p>
    <input type="text" id="j" name="j" class="loo" value="12" data-x="c">
    </p>
  • 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-25T12:26:16+00:00Added an answer on May 25, 2026 at 12:26 pm
    var highest = new Array();
    
    $('.loo').each(function(){
    
        if(!highest[$(this).data('x')] || parseInt($(this).val()) > highest[$(this).data('x')] )
            highest[$(this).data('x')] = parseInt($(this).val());          
    
    });
    

    This will loop through all instances of .loo and checks if there is no entry yet or if the current saved value is lower than the current elements value, in that case it will update the array entry.

    This will leave you with an array containing all max values for all possible values of data-x

    EDIT

    excuse me, some syntax errors were present.

    EDIT 2

    shorter version

    http://jsfiddle.net/kkbkb/1/

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

Sidebar

Related Questions

I have a form which posts data to the same page. Based on the
I have been reading on the different question talking about selecting unique nodes in
When you want to recursively enumerate a hierarchical object, selecting some elements based on
I got to thinking about font (typeface) selection today. A site I did for
About 6 months ago I rolled out a site where every request needed to
About a year ago, I picked up Scott Ambler's Refactoring Databases: Evolutionary Database Design
About 2 years ago I dropped windows from my home PC and switched 100%
About a half dozen times now, I’ve been doing a regular chore in Visual
Thinking about getting into .net technology project management I've had plenty of experience with
Thinking about a Windows-hosted build process that will periodically drop files to disk to

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.