C4 Week3
C4 Week3
This slide deck consists of slides used in 2 lecture videos in Week 4. Below
is a list of shortcut hyperlinks for you to jump into specific sections.
http://www.dj4e.com/code/jquery
http://www.dj4e.com/code/jquery.zip
Vanilla JavaScript (1995)
<script type="text/javascript">
document.write("<p>Hello World</p>")
</script>
https://www.dj4e.com/code/javascript/js-01.htm
http://en.wikipedia.org/wiki/Document_Object_Model
Browser Linux
settings.py Django
views.py
D
O
Parse
Response
DOM
Views Templates
M forms.py
Database
Shell
JavaScript Models
model.py
/admin
admin.py
Document Object Model
dom-01.htm
console.dir(document.getElementById('person'));
<a href="#"
onclick="document.getElementById('stuff').innerHTML='BACK';return false;">
Back</a>
<a href="#"
onclick="document.getElementById('stuff').innerHTML='FORTH';return false;">
Forth</a>
</p>
<p>
Hello <b><span id="stuff">Stuff</span></b> there.
http://jquery.org
John Resig
• Started jQuery in 2005 to make
his web development projects
easier
• Released in 2006
•http://docs.jquery.com/Main_Page
•http://api.jquery.com/
•http://jqueryui.com/demos/
• This lecture will only cover the basic elements of low-
level jQuery.
<html>
jquery/jq-01.htm
<head>
</head>
<body>
<p>Here is some awesome page content</p>
<script type="text/javascript" src="jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
alert("Hello jQuery World!");
console.log('Hello jQuery..');
});
</script>
</body> jquery/jq-01.htm
<html
jquery/jq-02.htm jquery/jq-02.htm
<head>
</head>
<body>
<script type="text/javascript" src="jquery.min.js">
</script>
<script type="text/javascript">
$(window).resize(function() {
console.log('.resize() called. width='+
$(window).width()+' height='+$(window).height());
});
</script>
<p>Here is some awesome page content</p>
</body>
http://api.jquery.com/resize/
<p id="para">Where is the spinner?
jquery/jq-03.htm
<imgjquery/jq-03.htm
id="spinner" src="spinner.gif" height="25"
style="vertical-align: middle; display:none;">
</p><p> Where is the spinner?
<a href="#" id="tog">Toggle</a> | Toggle | Red
<a href="#" id="red">Red</a>
</p>
<script type="text/javascript">
$(document).ready(function() { Where is the spinner?
$("#tog").on('click', function() { Toggle | Red
$('#spinner').toggle();
});
$("#red").on('click', function() {
$('#para').css('background-color', 'green');
});
Where is the spinner?
}); Toggle | Red
</script>
<p>
<a href="#" id="the-href">More</a> jq-04.htm
jq-04.htm
</p>
<ul id="the-list">
<li>First Item</li>
</ul>
<script type="text/javascript"
src="jquery.min.js"> </script>
<script>
counter = 1;
$(document).ready(function(){
$("#the-href").on('click', function() {
console.log('Clicked');
$('#the-list').append('<li>The counter is '+counter+'</li>');
counter++;
});
});
</script>
Improving Browsers…
// Vanilla: Iterate over the nodelist of elements to hide all instances of .box
document.querySelectorAll(".box").forEach(box => { box.style.display = "none" }
https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/
Summary
• Initialization setup
• Event handling
• DOM selection
• DOM manipulation