Created
January 6, 2018 00:35
-
-
Save ldco2016/0160fb6375f90968b93f68352fa4fe9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is vanilla JS to add dynamic behavior to | |
// a webpage. Can you figure out what this does? | |
const login = document.getElementById('login'); | |
const loginMenu = document.getElementById('loginMenu'); | |
login.addEventListener('click', () => { | |
if(loginMenu.style.display === 'none'){ | |
loginMenu.style.display = 'inline'; | |
} else { | |
loginMenu.style.display = 'none'; | |
} | |
}); | |
// In the above example, JavaScript is used to apply behavior | |
// to an HTML element with id login. The behavior allows a user | |
// to click a LOGIN button that toggles a login form. | |
// The code below accomplishes the same behavior with jQuery. | |
$('#login').click(() => { | |
$('#loginMenu').toggle() | |
}); | |
// In this example, the same toggle functionality is accomplished | |
// using just three lines of code. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment