I am trying to get the value of an input. Here is what my form looks like:
This is the HTML for it:
<label for="userName"></label>
<input type="text" class="form-input plain-text" id="userName" placeholder="Username">
Here is the jQuery to get its value and log it:
$("#loginSubmit").click(function() {
var userName = $("#userName").val();
console.log(userName);
});
But when I type in some text and hit the login button that has the id #userName, the console returns this:
Why does this not output dwedwed in the console?
Thanks
Solution found in comments
Debugging: I found I have more than one input with the same ID
Immediate reasons I can see are:
Other than the above, it's hard to determine what is going on without more code/information.
If its a matter of when you are attaching the listener, try adding $(document).ready() around your event listener.