user460114 user460114 - 1 year ago 77
Javascript Question

Count elements having a specified attribute

I need to count all elements having the attribute "ind", regardless of what the value of that attribute is.

<select name="region_id" class="selSumo selRelated" ind="1">

e.g. I guess and adaptation of

var cnt = jQuery(['ind']).length;

I have three different selects on the page, each with attribute "ind", but I get cnt = 1.

Answer Source

$("[ind]").length will give the count of all the elements with attribute ind

codepen URL for reference -


            <select name="region_id1" class="selSumo selRelated" ind="1">
              <select name="region_id" class="selSumo selRelated" >

                <div ind="1">1</div>

Hope this is helpful for you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download