Find and compare elements with matching attribute values in Jquery
<p>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.<br>
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.</p>

<pre><code>    &lt;script&gt;
    $(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 &gt; 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;
        }


    });
    &lt;/script&gt;
</code></pre>

<p>Html:</p>

<pre><code>    &lt;p&gt;
    &lt;input type="text" id="e" name="e" class="loo" value="1" data-x="a"&gt;
    &lt;/p&gt;
    &lt;p&gt;
    &lt;input type="text" id="f" name="f" class="loo" value="10" data-x="a"&gt;
    &lt;/p&gt;
    &lt;p&gt;
    &lt;input type="text" id="g" name="g" class="loo" value="37" data-x="b"&gt;
    &lt;/p&gt;
    &lt;p&gt;
    &lt;input type="text" id="h" name="h" class="loo" value="25" data-x="b"&gt;
    &lt;/p&gt;
    &lt;p&gt;
    &lt;input type="text" id="i" name="i" class="loo" value="11" data-x="c"&gt;
    &lt;/p&gt;
    &lt;p&gt;
    &lt;input type="text" id="j" name="j" class="loo" value="12" data-x="c"&gt;
    &lt;/p&gt;
</code></pre>
