<!DOCTYPE html> <html> <head> <title>Title of the page in the browser window</title> </head> <body> <p>The simplest possible web page</p> </body> </html>
<a href="www.google.com">A link to google</a>
<h1>A very large heading</h1> <h2>A smaller heading</h2> <h3>Smaller heading still</h3> <p>A paragraph</p> <a href="http://www.twitter.com">A link to twitter</a> <img alt="Google" src="http://www.google.com/images/srpr/logo11w.png"/>
<!-- Valid --> <a href="www.google.com"> <h1> Nice heading</h1> </a>
<!-- Invalid --> <a href="www.google.com"> <h1> Nice heading</a> </h1>
> > < < & & " "
<div id="content"> <p>Content <span class="inline-emphasis">here</span></p> </div>
id - unique on page, like a user
class - not unique, like a group
Used with CSS and JavaScript:
- Choose the element with an id
- Choose the elements with a class
p { text-align: left; }
For content matching this selector:
- Set the property to this value
p { text-align: left; }
<p class='emphasized' id='desc'>Information</p> // All elements with emphasized class will be bold .emphasized { font-weight: bold; } // The element with desc id will have a margin #desc { margin: 4px 2px; }
<p class="emphasized">Content</p> <p id="desc">Content</p>
// A p tag with emphasized class p.emphasized { font-weight: bold; } // A p tag with desc id p#desc { margin: 4px 2px; }
// elements with either class .emphasized, .interesting { font-size: 10px; }
// Element with interesting class, inside element with emphasized class .emphasized .interesting { font-style: italic; }
<p class="emphasized">Content</p> <span class="emphasized><p>Content</p></span>
// A p tag with emphasized class p.emphasized { font-weight: bold; } // A p tag of an emphasized class element (likely div or span) p .emphasized { font-weight: bold; }
var add = function(a, b) { return a + b; }
var a = 3; var b = 3.4; var c = 'Oh hai'; var d = null; var e = undefined;
function(arg) { console.log(arg); return arg; }
// Function declaration function func(arg) { console.log(arg); return arg; } // Function expression var func = function (arg) { console.log(arg); return arg; }
var sidebar = document.getElementById('sidebar'); sidebar.onclick = function(event) { console.log(event, 'clicked'); };
var sidebar = document.getElementById('sidebar'); console.log(sidebar.outerHTML); console.log(sidebar.innerHTML); sidebar.innerHTML = '<p>New content</p>'; sidebar.hide(); sidebar.show();
http://www.w3schools.com/js/js_htmldom_navigation.asp
var sidebar = $('#sidebar'); sidebar.html('<p>New Content</p>');
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<body> <p id="message">JavaScript is Fun</p> <button id="bounce">Click here to bounce</button> <script> $("button#bounce").click(function() { $("p#message").slideUp(500).slideDown(500); }); </script> </body>
$("button#bounce").click(function() { $("p#message") .slideUp(500) .slideDown(500, function() { $(this).css('color', 'red'); }); });
$("button#bounce").click(function() { $("p#message") .css('color', 'red') .slideUp(500) .slideDown(500, function() { $(this).css('color', 'black'); }); });
$("button#bounce").click(function(){ var $el = $('p#message'), el_orig_color = $el.css('color'); $el .css('color', 'red') .slideUp(500) .slideDown(500, function(){ $(this).css('color', el_orig_color); }); });
Saved in a fiddle - http://jsfiddle.net/sz7n3vrj/
// HTML body <form> <label>Make:</label> <select name="make"> <option value="ford">Ford</option> <option value="chev">Chevrolet</option> <option value="toyo">Toyota</option> <option value="volk">Volkswagen</option> </select> <br/> <label>Model:</label> <select name="model"> <option value="NA">--Please choose a Make--</option> </select> <input type="submit" value="Submit"> </form>
// JavaScript var make_model_lookup = { 'ford': [ ['taur', 'Taurus'], ['esco', 'Escort'] ], 'chev': [ ['cava', 'Cavalier'], ['volt', 'Volt'] ], 'toyo': [ ['camr', 'Camry'], ['coro', 'Corolla'] ], 'volk': [ ['jett', 'Jetta'], ['golf', 'Golf'] ] };
$('select[name=make]').change(function() { var $select_model = $('select[name=model]'), make_value = this.value, model_options_list = make_model_lookup[make_value]; $select_model.find('option').remove(); for(var i = 0; i < model_options_list.length; i++) { var model_value = model_options_list[i][0], model_display_value = model_options_list[i][1]; var model_option = '<option value="' + model_value + '">' + model_display_value + '</option>'; $select_model.append(model_option); } });
x = 3 // ... var weird_add = function(a, b) { x = a + 1; y = b + 1; return x + y - 2; } console.log(weird_add(10, 20)); console.log(x);
var x = 3 // ... var weird_add = function(a, b) { var x = a + 1; var y = b + 1; return x + y - 2; } console.log(weird_add(10, 20)); console.log(x);
"37" - 7 // 30 "37" + 7 // "377"
$("button#bounce").click(function() { $("p#message") .slideUp(500) .slideDown(500, function() { // Here, this is the current element $(this).css('color', 'red'); }); }); // Here, this is the window this === window; // true this.document === document; // true
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
// top of file 'use strict'; // OR function func(arg) { 'use strict'; // ... function body return x }
JavaScript and the DOM are often quirky
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |