Created
September 18, 2014 06:57
-
-
Save brookr/ec6617df5391fedac889 to your computer and use it in GitHub Desktop.
Demo code from Class 5
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>JavaScript & jQuery - Chapter 7: Introducing jQuery - Looping</title> | |
| <link rel="stylesheet" href="css/c07.css" /> | |
| </head> | |
| <body> | |
| <div id="page"> | |
| <h1 id="header">List</h1> | |
| <h2>Buy groceries</h2> | |
| <ul> | |
| <li id="one" class="hot"><em>fresh</em> figs</li> | |
| <li id="two" class="hot">pine nuts</li> | |
| <li id="three" class="hot">honey</li> | |
| <li id="four">balsamic vinegar</li> | |
| </ul> | |
| </div> | |
| <script src="js/jquery-1.11.0.js"></script> | |
| <script> | |
| $(function() { | |
| var originalBackgroundColor = $('li:first').css('background-color'); | |
| var newBackgroundColor = $('li:last').css('background-color'); | |
| $('ul').append('<p id="info"><input id="numberItems" type="text"></p>'); | |
| $('li').on({ | |
| mouseenter: function() { | |
| $(this).css({ | |
| 'background-color': newBackgroundColor, | |
| 'border': '1px solid #fff' | |
| }) | |
| $('#info').text("Class is: " + $(this).attr("id")); | |
| }, mouseleave: function() { | |
| $(this).css({ | |
| 'background-color': originalBackgroundColor, | |
| 'border-width': "0px" | |
| }) | |
| } | |
| }) | |
| $('input#numberItems').on('blur', function() { | |
| var count = $(this).val(); | |
| $('li').hide(); | |
| $('li:lt(' + count + ')').fadeIn(); | |
| }) | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment