When jQuery returns an array of DOM elements, I am struggling to understand how that differs from when jQuery returns a single DOM element, as in the code below:
<html>
<head>
<title>A simple login form</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
function validateInput() {
var input = $('input');
var passwordById = $("#password1");
var passwordByIndex = input[0];
// What's the difference between these?
passwordById.val(); // Value of password field
passwordByIndex.val(); // Undefined!
}
</script>
</head>
<body>
<form>
<h2>Username</h2>
<input type="text" id="username" required>
<h2>Password</h2>
<input type="password" id="password" required>
<input type="button" value="Submit" onClick="validateInput()">
</form>
</body>
I want to use passwordByIndex because I wish to iterate over array $('input').