| HTML | Meaning and Content |
| CSS | Presentation & Style |
| JavaScript & jQuery |
Scripting, manipulate the DOM |
Excellent resource: W3 Schools
A DOM manipulation library
jQuery is a JavaScript Library.
jQuery greatly simplifies JavaScript programming.
jQuery is easy to learn.
Easier to access elements (re-using CSS Selectors)
We have linked the jQuery library when we set up Bootstrap. If we had not taken this step, we would add jQuery the same way we have other files, using the CDN (Content Delivery Network).
<head>
...other elements...
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.0/dist/jquery.slim.min.js"></script>
</head>
Examples:
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".
<p> elements on a pageHere are some common DOM events:
| Mouse Events | Keyboard Events | Form Events | Document/Window Events |
|---|---|---|---|
| click | keypress | submit | load |
| dblclick | keydown | change | resize |
| mouseenter | keyup | focus | scroll |
| mouseleave | blur | unload |
Most DOM Events have equivalent jQuery methods
Assign a click event to all paragraphs on a page - $("p").click();
Now we have to create a function for what happens on that click:
$("p").click(function(){ $("p").click(function(){
// action goes here!! $(this).hide();
}); });
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
What do these refer to?
$(selector).hide(speed,callback);
$(selector).show(speed,callback);
The optional callback parameter is a function to be executed after the hide() or show() method completes (out of scope for this class)
Speed parameter specifies the speed of the hiding/showing, and can take the following values: "slow", "fast", or milliseconds.
fadeIn()
fadeOut()
fadeToggle()
fadeTo()
$(selector).fadeIn(speed,callback);
slideDown()
slideUp()
slideToggle()
$(selector).slideDown(speed,callback);
fadeToggle()
$(selector).animate({params},speed,callback);
$("button").click(function(){
$("div").fadeToggle("slow");
});
https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_animation1
<div class="container-fluid">
<div class="row">
<div class="colImg">
<img src="images/Bodhi.JPG" alt="Majestic White Cat" class="center">
<button type="button">Click here</button>
</div>
</div>
</div>This is the html referred to in the functions
<head>
<title>Page Title</title>
<script>
$(document).ready(function () {
$("img").slideToggle("slow");
})
$(function () {
$("nav").append("WOW, this is amazing!!!");
});
});
</script>
</head>
You can add the functions to the head tag
<nav>
<a id="index" style="font-style: italic;" href="./index.html">Index |</a>
<a id="feeding" href="./feeding.html">Feeding |</a>
<a id="playing" href="./playing.html">Play Time |</a>
</nav>
<div class="container-fluid">
<div class="row">
<div class="colImg">
<img src="images/Bodhi.JPG" alt="Majestic White Cat" class="center">
<button type="button">Click here</button>
</div>
</div>
</div>
You can add the functions at the end of your code right before the </body> tag
<body>
<script>
$(document).ready(function () {
$("img").slideToggle("slow");
})
$(function () {
$("nav").append("WOW, this is amazing!!!");
});
});
</script>
</body>
<nav>
<a id="index" style="font-style: italic;" href="./index.html">Index |</a>
<a id="feeding" href="./feeding.html">Feeding |</a>
<a id="playing" href="./playing.html">Play Time |</a>
</nav>
<div class="container-fluid">
<div class="row">
<div class="colImg">
<img src="images/Bodhi.JPG" alt="Majestic White Cat" class="center">
<button type="button">Click here</button>
</div>
</div>
</div>
This is the html referred to in the functions
You can add the functions to an external .js file
$(document).ready(function () {
$("button").click(function () {
$("img").slideToggle("slow");
})
$(function () {
$("nav").append("WOW, this is amazing!!!");
});
});
This is the html referred to in the functions
<nav>
<a id="index" style="font-style: italic;" href="./index.html">Index |</a>
<a id="feeding" href="./feeding.html">Feeding |</a>
<a id="playing" href="./playing.html">Play Time |</a>
</nav>
<div class="container-fluid">
<div class="row">
<div class="colImg">
<img src="images/Bodhi.JPG" alt="Majestic White Cat" class="center">
<button type="button">Click here</button>
</div>
</div>
</div>