Skip to content

Instantly share code, notes, and snippets.

@rogerwschmidt
Last active May 19, 2017 01:35
Show Gist options
  • Save rogerwschmidt/98f9aeadcc220aa530c2ac441fa90097 to your computer and use it in GitHub Desktop.
Save rogerwschmidt/98f9aeadcc220aa530c2ac441fa90097 to your computer and use it in GitHub Desktop.

Interactive Programming with jQuery

Objectives

Describe the parts of a jQuery event handler.

$('#buttonID').click(function(event){})

Create and invoke a click handler that is called on an element using jQuery.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="index.css" rel="stylesheet" type="text/css" />
    <script defer src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity_no="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script>
    <script defer src="index.js"></script>
  </head>
  <body>
    <button id="count">Click me!!</button>
    <p id="counter">0</p>
  </body>
</html>

Log the element that was clicked on using a callback.

Console.log the content of the the p element with id of content.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="index.css" rel="stylesheet" type="text/css" />
    <script defer src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity_no="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script>
    <script defer src="index.js"></script>
  </head>
  <body>
    <p id="content">Get this content</p>
  </body>
</html>

Use setTimeout, setInterval, and cancelTimeout to animate an HTML element.

Using setInterval(), make the background of the paragraph change colors.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="index.css" rel="stylesheet" type="text/css" />
    <script defer src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity_no="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script>
    <script defer src="index.js"></script>
  </head>
  <body>
    <div><span id="colorChanger">This paragraph changes colors!</span></div>
    
    
  </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment