Javascript is a programming language that
resides inside HTML documents to provide interactivity.
What we use JavaScript for?
- make websites respond to user interaction
- build apps and games (e.g. blackjack)
- access information on the Internet
- organize and present data (e.g. data visualization)
<script type="text/javascript" src="scriptname.js" >
Inside the html document we use the <script> tag
to declare a scripting language.
We can define two attributes: type and src
The language type and an external .js file.
Inside the html document we use the <script> tag
to declare a scripting language.
We can define two attributes: type and src
The language type and an external .js file.
Class Exercise: Hello World
- Make a <button> tag
- Style it with an external css
- Create a .js file to react to button click
- Alert prompt "Hello World!"
var myButton = document.querySelector( "button" );
myButton.addEventListener( "click", function( evt ) {
alert( "Hello World!" );
}, false);
- jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML.
- jQuery is the most popular JavaScript library in use today.
- Used in 80% of the top 10,000 websites.
- It takes complex tasks and wraps them into single line commands
www.jquery.com/download
<script type="text/javascript" src="jquery URL" >
We can download the jQuery .js file to exist alongside the project files or we can link to the external .js file hosted on public development servers.
Class Exercise: Hello World (revisited)
- Link to an external jQuery .js files
- Alert "Hello World!" on button click
$("button").click( function() {
alert("Hello World");
} ) ;
Techniques for adding animation to a web page
- .animate()
- .slideUp()
- .slideDown()
- .show()
- .hide()
- .fadeIn()
- .fadeOut()
Class Exercise: Apply animate() to a div
- Make a <div> container
- Style it with an external css
- Animate the margin-top and margin-left using jQuery
.animate( property, speed, callback );
Techniques for capturing mouse actions
- .click()
- .dblclick()
- .hover()
- .mousedown()
- .mouseover()
- .mouseleave()
- .mousemove()
Class Exercise: animate() a div using mouse hover()
- Make a <div> container
- Style it with an external css
- Animate using jQuery Mouse Event hover()
$("div").hover(function(){
$(this).animate({ width: "300px" });
}, function() {
$(this).animate({ width: "100px" });
});
Intro to Javascript
By fdu
Intro to Javascript
- 1,081