When it comes to using jQuery and finding the values of text fields, adding classes seems like a common practice. However, I am concerned about how this may impact page loading. Is it efficient for the browser to search for all these classes? In the past, I have been advised to minimize the number of classes used on controls.
I have around 12 controls that require unique classes to access their values. Because I am using asp.net, I cannot use the id attribute. Additionally, I am unable to utilize the ClientID due to the controls being within a table (with only one set of controls visible at a time).
For example:
<asp:TextBox ID="txtValue1" runat="server" CssClass="value1" Text='value1' />
<asp:TextBox ID="txtValue2" runat="server" CssClass="value2" Text='value2' />
<asp:TextBox ID="txtValue3" runat="server" CssClass="value3" Text='value3' />
...
var value1 = $('.value1').val();
var value2 = $('.value2').val();
var value3 = $('.value3').val();
It's worth noting that none of these class names will be defined in CSS.
Thank you
Edit:
While I understand that this method works, my concern lies with its impact on page loading. An answer (which appears to be deleted now) mentioned that the HTML parser disregards the classes, and the CSS parser only looks at defined classes. This implies that the classes would be completely ignored and have no effect on page load. Can someone confirm if this is accurate?