How can I select an element by name with jQuery?

jQueryWeb DevelopmentFront End Technology

To select an element by name with jQuery, use the name element for the input field. You can try to run the following code to select element by name


Live Demo

<!DOCTYPE html>
<script src=""></script>
     var sname = jQuery("#form1 input[name=sub]").val();


<form name="myForm" id="form1">
  Subject Name: <input type="text" name="sub" value="Java"/>
<button id="button1">Get</button>
Updated on 17-Feb-2020 07:52:51