Skip to content

Instantly share code, notes, and snippets.

@vapidbabble
Created January 19, 2018 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vapidbabble/70ce9bb34eff01a9c0936192f0d5f56c to your computer and use it in GitHub Desktop.
Save vapidbabble/70ce9bb34eff01a9c0936192f0d5f56c to your computer and use it in GitHub Desktop.
jQuery 101 - Mini Challenge 3
<html>
<head>
<title>jQuery Mini Challenge 3</title>
</head>
<body>
<header>
<h1>jQuery Click Events</h1>
</header>
<section>
<article>
<h3>.val()</h3>
<p>The .val() method is primarily used to get the values of form elements such as input, select and textarea. When called on an empty collection, it returns undefined.</p>
</article>
<article>
<h3>.click()</h3>
<p>The click event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event.</p>
</article>
</section>
<section>
<h3>Login Form</h3>
<form action="">
<label for="email">Email</label>
<input type="email" id="emailField">
<br>
<label for="password">Password</label>
<input type="password" id="passwordField">
<br>
<button type="button" id="submit-button">Submit</button>
</form>
<br>
</section>
<footer>
<p>Source: <a href="https://jquery.com/">www.jquery.com</a></p>
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</body>
</html>
$(document).ready(function() {
//1. Add a .click() event handler to the submit button using its id "submit-button" so that when the button is clicked, log to the console "Submit button was clicked"
//2. In the event handler function, get the values the user enters in the email and password fields in the form so that when the submit button is clicked, log to console, the values from the input fields in the form.
var btnClicked = function(){
console.log("Submit button was clicked");
var emailField = $("#emailField").val();
console.log("User email is: " + emailField);
var passwordField = $("#passwordField").val();
console.log("User password is: " + passwordField);
}
$("#submit-button").click(btnClicked);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment