SlideShare a Scribd company logo
JavaScript
What can I use it for?
• Add/remove/modify content
• Set CSS styles, add/remove classes
• Show/hide/animate parts of the page
• React to events (clicks, typing, etc.)
• And much, much more!
Basic Concept -
Comments
// this line doesn't do anything!
/* These series of lines
is a bit longer but it
also doesn't do anything! */
$('a').hide(); // hide 'a'
$('a').hide(); // hide all links
$('a').hide(); // hide links while we validate them
Basic Concept -
Variables
var classes = 'products rocks monkeys';
var num = 2;
classes = classes + ' another';
// now: products rocks monkeys another
num = num * 2;
// now: 4
Basic Concept -
Functions
// assigning a function to a variable
// so we can call it several times
var test = function(message, count) {
count = count * 2;
console.log(message, count);
};
test('hello!', 1);
test('hello again!', 2);
// using a function to delay work
$(document).ready(
function() {
alert('document is ready!');
}
);
Basic Concept - Scope
var test = function(message, count) {
poorForm = 'probably a mistake';
var test = 1;
console.log(message, count, test, poorForm);
};
test('hello!', 1);
Basic Concept - jQuery
// locate zero or more things on the page:
$('css selector');
// do something with them
$('css selector').method();
e.g.
$('a') // gets all links
$('a.prods') // gets all links with prods class
$('a').hide(); // hide all links
$('a.prods').hide(); // hide links with prods class
$('a.misses').hide(); // no matches? no worries!
Getting setup to run JS
• Include jQuery on the page
<script src="http://ajax.googleapis.com/ajax/libs/
jquery/1.9.0/jquery.min.js" type="text/javascript"></
script>
Getting setup to run JS
• Add a script block to your page
<script type="text/javascript">
$(document).ready(function() {
/* my fancy JS code goes here! */
});
</script>
Simple JS Example
• Lets turn all links on the page green
<script type="text/javascript">
$(document).ready(function() {
$('a').css('color', 'green');
});
</script>
Interactive JS Example
• Lets hide links when they are clicked
<script type="text/javascript">
$(document).ready(function() {
$('a').css('color', 'green');
$('a').click(function() {
$(this).fadeOut();
return false;
});
});
</script>
Do I need to use
jQuery?
• No! But a JavaScript framework sure helps.
• Cross-Browser Issues
• More compact code
Example Fade Out
• Plain JS
<script type="text/javascript">
document.addEventListener(
'DOMContentLoaded',
function(){
var s = document.getElementById('thing').style;
s.opacity = 1;
var fade = function(){
s.opacity = s.opacity - 0.1;
if (s.opacity < 0) {
s.display = "none";
} else {
setTimeout(fade, 40);
}
};
fade();
}
);
</script>
Example Fade Out
• jQuery
<script src="http://ajax.googleapis.com/ajax/libs/
jquery/1.9.0/jquery.min.js" type="text/javascript"></
script>
<script type="text/javascript">
$(document).ready(function() {
$('#thing').fadeOut();
});
</script>
Further Reading &
Plugins
• AJAX/JSON
• WebRTC
• Offline Storage
• Phonegap
• http://www.unheap.com/
• http://jqueryui.com/

More Related Content

What's hot (20)

PPT
Yuihacku iitd-sumana
Sumana Hariharan
 
PPTX
webstudy jquery
Seungho Han
 
PDF
OUTDATED (Encore)
Stefan Adolf
 
PDF
Front End Development - Beyond Javascript (Robin Cannon)
Future Insights
 
PPTX
Put a little Backbone in your WordPress
adamsilverstein
 
PDF
Casl. isomorphic permission management.pptx
Sergiy Stotskiy
 
PDF
Owasp & php
Ahmed Kamel Taha
 
PDF
Intro to jquery
Dan Pickett
 
PPT
Javascript
timsplin
 
PPT
Jquery
Pushkar Dutt
 
PPTX
Jquery image slider
Ishaq Shinwari
 
DOCX
Div id
Nelson Dionizio
 
PDF
Mume JQueryMobile Intro
Gonzalo Parra
 
PPT
How Not to Build a WordPress Plugin
Will Norris
 
PDF
JavaScript the Smart Way - Getting Started with jQuery
katbailey
 
PDF
Ember: Guts & Goals
Bob Lail
 
PDF
Game jump: frontend introduction #1
Sebastian Pożoga
 
PPTX
jQuery presentation
Mahesh Reddy
 
PPSX
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
PDF
Lightning Talk: Making JS better with Browserify
crgwbr
 
Yuihacku iitd-sumana
Sumana Hariharan
 
webstudy jquery
Seungho Han
 
OUTDATED (Encore)
Stefan Adolf
 
Front End Development - Beyond Javascript (Robin Cannon)
Future Insights
 
Put a little Backbone in your WordPress
adamsilverstein
 
Casl. isomorphic permission management.pptx
Sergiy Stotskiy
 
Owasp & php
Ahmed Kamel Taha
 
Intro to jquery
Dan Pickett
 
Javascript
timsplin
 
Jquery
Pushkar Dutt
 
Jquery image slider
Ishaq Shinwari
 
Mume JQueryMobile Intro
Gonzalo Parra
 
How Not to Build a WordPress Plugin
Will Norris
 
JavaScript the Smart Way - Getting Started with jQuery
katbailey
 
Ember: Guts & Goals
Bob Lail
 
Game jump: frontend introduction #1
Sebastian Pożoga
 
jQuery presentation
Mahesh Reddy
 
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
Lightning Talk: Making JS better with Browserify
crgwbr
 

Viewers also liked (17)

PPT
Methodes van plaagbestrijding
Yentl Loeckx
 
PDF
Develop Your CMS In Your CMS
p4geoff
 
PPTX
Richsmanroom
Rich Keilholtz
 
PPTX
Eenjarige 4 Tt
Yentl Loeckx
 
PPTX
Visual Resume
thaz202
 
PPTX
How to start a business
jaseemkmch
 
PDF
04 sorting
martchasera92
 
PPTX
Spenser's Visual Resume
SMWinters33
 
PPTX
Rich’s man room
Rich Keilholtz
 
PPTX
Groene week
Yentl Loeckx
 
PPT
Methodes van plaagbestrijding
Yentl Loeckx
 
PPTX
Eenjarige 3 tt
Yentl Loeckx
 
PDF
Socialarc - Our Manifesto
Socialarc
 
PPTX
Groenten 3 tt
Yentl Loeckx
 
PDF
Socialarc - Is Your Facebook Content Getting Lost In The Wild?
Socialarc
 
PDF
Railsbridge intro
p4geoff
 
PPT
Visual Resume
cepeak3
 
Methodes van plaagbestrijding
Yentl Loeckx
 
Develop Your CMS In Your CMS
p4geoff
 
Richsmanroom
Rich Keilholtz
 
Eenjarige 4 Tt
Yentl Loeckx
 
Visual Resume
thaz202
 
How to start a business
jaseemkmch
 
04 sorting
martchasera92
 
Spenser's Visual Resume
SMWinters33
 
Rich’s man room
Rich Keilholtz
 
Groene week
Yentl Loeckx
 
Methodes van plaagbestrijding
Yentl Loeckx
 
Eenjarige 3 tt
Yentl Loeckx
 
Socialarc - Our Manifesto
Socialarc
 
Groenten 3 tt
Yentl Loeckx
 
Socialarc - Is Your Facebook Content Getting Lost In The Wild?
Socialarc
 
Railsbridge intro
p4geoff
 
Visual Resume
cepeak3
 
Ad

Similar to Railsbridge javascript (20)

PPTX
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
PPTX
Javascript note for engineering notes.pptx
engineeradda55
 
PDF
8.-Javascript-report powerpoint presentation
JohnLagman3
 
PDF
Build a game with javascript (may 21 atlanta)
Thinkful
 
PDF
Presentation on htmlcssjs-130221085257-phpapp02.pdf
MeetRajani2
 
PPTX
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
PDF
Introduction to web programming with JavaScript
T11 Sessions
 
PPT
Applied component i unit 2
Pramod Redekar
 
PDF
JavaScript
tutorialsruby
 
PDF
JavaScript
tutorialsruby
 
PDF
Build a game with javascript (april 2017)
Thinkful
 
PPTX
Javascript & Jquery
Gurpreet singh
 
DOCX
What is Web designing.docx? What are its components
ManjuGoyal4
 
PDF
Training javascript 2012 hcmut
University of Technology
 
PDF
WT UNIT 2 presentation :client side technologies JavaScript And Dom
SrushtiGhise
 
PDF
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
PDF
Wt unit 2 ppts client sied technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PPTX
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
ArjayBalberan1
 
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
Javascript note for engineering notes.pptx
engineeradda55
 
8.-Javascript-report powerpoint presentation
JohnLagman3
 
Build a game with javascript (may 21 atlanta)
Thinkful
 
Presentation on htmlcssjs-130221085257-phpapp02.pdf
MeetRajani2
 
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
Introduction to web programming with JavaScript
T11 Sessions
 
Applied component i unit 2
Pramod Redekar
 
JavaScript
tutorialsruby
 
JavaScript
tutorialsruby
 
Build a game with javascript (april 2017)
Thinkful
 
Javascript & Jquery
Gurpreet singh
 
What is Web designing.docx? What are its components
ManjuGoyal4
 
Training javascript 2012 hcmut
University of Technology
 
WT UNIT 2 presentation :client side technologies JavaScript And Dom
SrushtiGhise
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
Wt unit 2 ppts client sied technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Week 4 - jQuery + Ajax
baygross
 
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
ArjayBalberan1
 
Ad

Railsbridge javascript

  • 2. What can I use it for? • Add/remove/modify content • Set CSS styles, add/remove classes • Show/hide/animate parts of the page • React to events (clicks, typing, etc.) • And much, much more!
  • 3. Basic Concept - Comments // this line doesn't do anything! /* These series of lines is a bit longer but it also doesn't do anything! */ $('a').hide(); // hide 'a' $('a').hide(); // hide all links $('a').hide(); // hide links while we validate them
  • 4. Basic Concept - Variables var classes = 'products rocks monkeys'; var num = 2; classes = classes + ' another'; // now: products rocks monkeys another num = num * 2; // now: 4
  • 5. Basic Concept - Functions // assigning a function to a variable // so we can call it several times var test = function(message, count) { count = count * 2; console.log(message, count); }; test('hello!', 1); test('hello again!', 2); // using a function to delay work $(document).ready( function() { alert('document is ready!'); } );
  • 6. Basic Concept - Scope var test = function(message, count) { poorForm = 'probably a mistake'; var test = 1; console.log(message, count, test, poorForm); }; test('hello!', 1);
  • 7. Basic Concept - jQuery // locate zero or more things on the page: $('css selector'); // do something with them $('css selector').method(); e.g. $('a') // gets all links $('a.prods') // gets all links with prods class $('a').hide(); // hide all links $('a.prods').hide(); // hide links with prods class $('a.misses').hide(); // no matches? no worries!
  • 8. Getting setup to run JS • Include jQuery on the page <script src="http://ajax.googleapis.com/ajax/libs/ jquery/1.9.0/jquery.min.js" type="text/javascript"></ script>
  • 9. Getting setup to run JS • Add a script block to your page <script type="text/javascript"> $(document).ready(function() { /* my fancy JS code goes here! */ }); </script>
  • 10. Simple JS Example • Lets turn all links on the page green <script type="text/javascript"> $(document).ready(function() { $('a').css('color', 'green'); }); </script>
  • 11. Interactive JS Example • Lets hide links when they are clicked <script type="text/javascript"> $(document).ready(function() { $('a').css('color', 'green'); $('a').click(function() { $(this).fadeOut(); return false; }); }); </script>
  • 12. Do I need to use jQuery? • No! But a JavaScript framework sure helps. • Cross-Browser Issues • More compact code
  • 13. Example Fade Out • Plain JS <script type="text/javascript"> document.addEventListener( 'DOMContentLoaded', function(){ var s = document.getElementById('thing').style; s.opacity = 1; var fade = function(){ s.opacity = s.opacity - 0.1; if (s.opacity < 0) { s.display = "none"; } else { setTimeout(fade, 40); } }; fade(); } ); </script>
  • 14. Example Fade Out • jQuery <script src="http://ajax.googleapis.com/ajax/libs/ jquery/1.9.0/jquery.min.js" type="text/javascript"></ script> <script type="text/javascript"> $(document).ready(function() { $('#thing').fadeOut(); }); </script>
  • 15. Further Reading & Plugins • AJAX/JSON • WebRTC • Offline Storage • Phonegap • http://www.unheap.com/ • http://jqueryui.com/