01.03.JS Output
01.03.JS Output
JavaScript Output
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
Interactivity
• HTML5 and CSS3 are not really
interactive
• New elements and pseudo-classes can
only go so far
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
JavaScript Output
• JavaScript doesn’t have a built-in
print function
• Data is displayed via
– an alert box using window.alert()
– a prompt using window.prompt()
– HTML output using document.write()
– HTML element using innerHTML()
– the browser console using console.log()
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
alert()
• In JS, an alert is a pop-up window that
displays information
alert(“My Message Here”);
prompt()
• Very similar to alert, but wants input.
document.write()
• What if we want something permanent?
• document.write() writes directly to the page
document.write()
• Not usually recommended since it can
easily be misused
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
innerHTML
• To change the contents of the DOM, use
innerHTML combined with the element you
want to change no parentheses!!
console.log()
• This option write the data to the browser
console
console.log(“Leave a secret message”);
The console
• You should be utilizing the console by
now
• Does more than take “print” statements,
also provides debugging information for
JavaScript, HTML and CSS
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
Debugging
• Safari: Preferences Advanced Check the
Show development menu in menu box”
• Google Chrome: Developer JavaScript
Console
• Firefox: Tools Console
• Edge: F12
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
Review
• Right now, we are doing simple things
with output
• As you learn more, the power grows
INTERACTIVITY
01.03 Output WITH JAVASCRIPT
Acknowledgements/Contributions
These slides are Copyright 2015- Colleen van Lent as part of
http://www.intro-webdesign.com/ and made available under a Creative
Commons Attribution Non-Commercial 4.0 License. Please maintain
this last slide in all copies of the document to comply with the attribution
requirements of the license. If you make a change, feel free to add
your name and organization to the list of contributors on this page as
you republish the materials.