Hi,
Please let me know how to acesss a single element using Class Name in jQuery?
<input type="text" class="textbox" /> <input type="text" class="textbox" /> <input type="text" class="textbox" />
Hi makenzi.exc,
Use jQuery class selector.
Refer below example.
HTML
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <input type="text" class="textbox" /><br /><br /> <input type="text" class="textbox" /><br /><br /> <input type="text" class="textbox" /><br /><br /> <input id="btnSet" type="button" value="Set Value" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#btnSet").click(function () { // Referencing TextBoxes. var textboxes = $(".textbox"); //Set the First TextBox value. textboxes.eq(0).val("Mudassar Khan"); //Set the Second TextBox value. textboxes.eq(1).val("Maria Anders"); //Set the Third TextBox value. textboxes.eq(2).val("John Wales"); }); }); </script> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.