Skip to content

Instantly share code, notes, and snippets.

@kevinlee702
Forked from dbc-challenges/jquery_example.html
Last active August 29, 2015 13:58
Show Gist options
  • Save kevinlee702/9944372 to your computer and use it in GitHub Desktop.
Save kevinlee702/9944372 to your computer and use it in GitHub Desktop.
Intro to jQuery for Phase 0
<!DOCTYPE html>
<html>
<head>
<title>DOM manipulation with jQuery</title>
<!-- Add a link to jQuery CDN here script here -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery_example.js"></script>
</head>
<body>
<h1> Hello. Welcome to the jQuery DOM Manipulation Challenge! </h1>
<div class="mascot">
<h1 id="logo"> My DBC Mascot </h1>
<img id="peepers" src="http://ebmedia.eventbrite.com/s3-build/images/1238516/37120493192/1/logo.jpg">
</div>
<p>Click on the pic!</p>
<button id="clickme">Click Me</button>
<button id="clickme2">Reset</button>
<button id="clickme3">Shrink Me</button>
</body>
</html>
$(document).ready(function(){
//RELEASE 0:
//Link this script and the jQuery library to the jquery_example.html file and analyze what this code does.
$('body').css({'background-color': 'pink'})
//RELEASE 1:
//Add code here to select elements of the DOM
bodyElement = $('body');
//RELEASE 2:
// Add code here to modify the css and html of DOM elements
$("h1").css({"color": "limegreen", "border": "3px solid darkgreen", "visibility": "visible"});
$("h1").css({"width": "48%"});
$("h1").css({"text-shadow": "2px 2px grey"});
$("h1").css({"box-shadow": "10px 10px 7px grey"});
$("#logo").html("SPRING PEEPERS MASCOT!");
$("#logo").css({"color": "green", "font-size": "2em"});
$("#logo").css({"text-shadow": "2px 2px grey", "width": "25%"});
//RELEASE 3: Event Listener
// Add the code for the event listener here
$('img').on('mouseover', function(e){
e.preventDefault()
$(this).attr('src', 'http://www.herprman.com/wp-content/gallery/spring-peeper/Peep5.jpg')
});
$('img').on('click', function(e){
e.preventDefault()
$(this).attr('src', 'http://ebmedia.eventbrite.com/s3-build/images/1238516/37120493192/1/logo.jpg')
});
//RELEASE 4 : Experiment on your own
$( "#clickme" ).click(function() {
$( "#peepers").animate({
width: "70%",
marginLeft: "0.6in",
borderWidth: "10px"
}, 1500 );
});
$( "#clickme2" ).click(function() {
$( "#peepers").css({
width: "",
marginLeft: "",
borderWidth: "",
opacity: 1
});
});
$( "#clickme3" ).click(function() {
$( "#peepers").animate({
width: "20%",
left: "+=50",
borderWidth: "2px"
}, 5000, function() {
// Animation complete.
});
});
}) // end of the document.ready function: do not remove or write DOM manipulation below this.

###Reflection Jquery is definitely fun to play with and the missing piece to interact with webpages. I see there are a lot of tricks to learn so I can't wait to see more advanced things we can do with this knowledge. http://www.codecademy.com/tracks/jquery is definitely a good starting point to get familiar with the syntax and learn it in smaller steps. In release 1: remove var and it will work. Good tips in the comment sections. This was a fun exercise and I think an important one to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment