Skip to content Skip to sidebar Skip to footer

Jquery - Count Similar Data Fields/class Name In Html Form

I want to get the count of data-fields in HTML form using JavaScript or jQuery ).length; alert (x);
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputdata-table="assessment_rating"data-field="x_PERFORMANCE_MEASURE"name="x1_PERFORMANCE_MEASURE"id="x1_PERFORMANCE_MEASURE"placeholder="Performance Measure"value=""class="form-control"type="text">

Of course since your example didn't include the original #ewTableHeaderCell table header cell, I've omitted it out of my snippet. But you get the idea. in your case it is:

var x = $('#ewTableHeaderCell input[data-field="x_PERFORMANCE_MEASURE"]').length;

Since uses css selectors under the hood, click the link to learn more.

Solution 2:

Since x_PERFORMANCE_MEASURE is not a class, you can't use class selector .

Select it using attribute selector:

$(document).ready(function() {
  alert($('#ewTableHeaderCell [data-field="x_PERFORMANCE_MEASURE"]').length);
})
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><spanid="ewTableHeaderCell"><inputdata-table="assessment_rating"data-field="x_PERFORMANCE_MEASURE"name="x1_PERFORMANCE_MEASURE"id="x1_PERFORMANCE_MEASURE"placeholder="Performance Measure"value=""class="form-control"type="text"></span>

Post a Comment for "Jquery - Count Similar Data Fields/class Name In Html Form"