Skip to content

Instantly share code, notes, and snippets.

@federicorudolf
Last active June 5, 2016 22:04
Show Gist options
  • Save federicorudolf/5c445b5aed278f310534e764ae0c9446 to your computer and use it in GitHub Desktop.
Save federicorudolf/5c445b5aed278f310534e764ae0c9446 to your computer and use it in GitHub Desktop.
Topico 1 - JavaScript
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Topico 1 - JavaScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>
<section class="fade-in">
<p><h1>Hello World!</h1></p>
</section>
<script type="text/javascript">
$(function(){
$(document).ready
$(".fade-in").hide().fadeIn(5000);
});
</script>
<button id="button" type="button"> Click Me </button>
<script>
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
xhr = new ActiveXObject("Microsoft.XMLHTTP")
}
function MyFunction(){
if (xhr.readyState == 0 || xhr.readyState == 4) {
xhr.open("get", "http://api.icndb.com/jokes/random", true);
xhr.onreadystatechange = handleResponse;
xhr.send(null);
}
else {
document.getElementById("section").fontcolor("red");;
}
}
function handleResponse(){
if (xhr.readyState == 4 || xhr.status == 200){
var returnResponse = xhr.responseText;
document.getElementById("section").innerHTML = returnResponse
}
}
document.getElementById ("button").addEventListener("click", function () {
MyFunction ();
});
//http://api.icndb.com/jokes/random
</script>
</body>
</html>
*{
}
body {
}
section {
text-align: center;
opacity: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment