Skip to content

Instantly share code, notes, and snippets.

@porfidev
Created September 19, 2019 18:14
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 porfidev/13174f2bc035c323b99ac8f74d4c0e25 to your computer and use it in GitHub Desktop.
Save porfidev/13174f2bc035c323b99ac8f74d4c0e25 to your computer and use it in GitHub Desktop.
Refactor de tutorial #1 Mostrar y Ocultar Divs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Tutorial jQuery Remasterizado</title>
<link href="style.css" rel="stylesheet">
</head>
<body>
<button id="showContainer" type="button">Mostrar mensaje</button>
<button id="hideContainer" type="button">Ocultar mensaje</button>
<div class="container hidden">
Esta div se esta mostrando sin embargo puede ser cualquier elemento
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"
></script>
<script>
$(window).on("load", assignEvents);
function assignEvents() {
$("#showContainer").on("click", mostrar);
$("#hideContainer").on("click", ocultar);
}
function mostrar() {
$("div").show("slow");
}
function ocultar() {
$("div").hide("slow");
}
</script>
</body>
</html>
.container {
background-color: #9c0;
border-color: #063;
border-style: dotted;
border: thin;
width: 200px;
height: 200px;
}
.hidden {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment