Add a mouse interaction
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FIT1050 Web Fundamentals - Week 9</title>
<link href="style.css" type="text/css" rel="stylesheet" media="screen">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
function showMessage() {
alert("JaveScript!")
}
</script>
</head>
<body>
<h1>FIT1050 Web Fundamentals</h1>
<h2>Week 9 - JavaScript and jQuery</h2>
<p id="filters">
Filter:
<button data-filter=".book, .tv, .movie, .game">All</button>
<button data-filter=".book">Books</button>
<button data-filter=".tv">TV</button>
<button data-filter=".movie">Movies</button>
<button data-filter=".game">Games</button>
</p>
<p id="products">
<!-- images sourced from: www.bigw.com.au -->
<img src="images/small/aclashofkings.jpg" alt="" class="book" />
<img src="images/small/blazingsaddles.jpg" alt="" class="movie" />
<img src="images/small/bones.jpg" alt="" class="tv" />
<img src="images/small/captainamerica.jpg" alt="" class="movie" />
<img src="images/small/chappie.jpg" alt="" class="movie" />
<img src="images/small/criminalminds.jpg" alt="" class="tv" />
<img src="images/small/doctorwho.jpg" alt="" class="tv" />
<img src="images/small/fifa16.jpg" alt="" class="game" />
<img src="images/small/fullhouse.jpg" alt="" class="tv" />
<img src="images/small/gameofthrones.jpg" alt="" class="tv" />
<img src="images/small/goldenlion.jpg" alt="" class="book" />
<img src="images/small/gosetawatchman.jpg" alt="" class="book" />
<img src="images/small/gtav.jpg" alt="" class="game" />
<img src="images/small/halo5.jpg" alt="" class="game" />
<img src="images/small/makeme.jpg" alt="" class="book" />
<img src="images/small/monstersinc.jpg" alt="" class="movie" />
<img src="images/small/nba2k16.jpg" alt="" class="game" />
<img src="images/small/plentymore.jpg" alt="" class="book" />
<img src="images/small/pulpfiction.jpg" alt="" class="movie" />
<img src="images/small/sims4.jpg" alt="" class="game" />
</p>
<script src="script.js">
// showMessage()
</script>
</body>
</html>
document.querySelector('h1').addEventListener('click',showMessage);
Implementing interactivity with jQuery
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FIT1050 Web Fundamentals - Week 9</title>
<link href="style.css" type="text/css" rel="stylesheet" media="screen">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="script.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
</head>
<body>
<h1>FIT1050 Web Fundamentals</h1>
<h2>Week 9 - JavaScript and jQuery</h2>
<p id="filters">
Filter:
<button data-filter=".book, .tv, .movie, .game">All</button>
<button data-filter=".book">Books</button>
<button data-filter=".tv">TV</button>
<button data-filter=".movie">Movies</button>
<button data-filter=".game">Games</button>
</p>
<p id="products">
<!-- images sourced from: www.bigw.com.au -->
<img src="images/small/aclashofkings.jpg" alt="" class="book" />
<img src="images/small/blazingsaddles.jpg" alt="" class="movie" />
<img src="images/small/bones.jpg" alt="" class="tv" />
<img src="images/small/captainamerica.jpg" alt="" class="movie" />
<img src="images/small/chappie.jpg" alt="" class="movie" />
<img src="images/small/criminalminds.jpg" alt="" class="tv" />
<img src="images/small/doctorwho.jpg" alt="" class="tv" />
<img src="images/small/fifa16.jpg" alt="" class="game" />
<img src="images/small/fullhouse.jpg" alt="" class="tv" />
<img src="images/small/gameofthrones.jpg" alt="" class="tv" />
<img src="images/small/goldenlion.jpg" alt="" class="book" />
<img src="images/small/gosetawatchman.jpg" alt="" class="book" />
<img src="images/small/gtav.jpg" alt="" class="game" />
<img src="images/small/halo5.jpg" alt="" class="game" />
<img src="images/small/makeme.jpg" alt="" class="book" />
<img src="images/small/monstersinc.jpg" alt="" class="movie" />
<img src="images/small/nba2k16.jpg" alt="" class="game" />
<img src="images/small/plentymore.jpg" alt="" class="book" />
<img src="images/small/pulpfiction.jpg" alt="" class="movie" />
<img src="images/small/sims4.jpg" alt="" class="game" />
</p>
<script src="script.js">
swal("Hello world!");
</script>
</body>
</html>
$( 'button' ).click( filterItems );
function filterItems() {
let button = this;
let selector = $( button ).data( 'filter' );
console.log( selector );
$('#products img').not(selector).hide(500);
$(selector).show(500);
// $( '#products img' ).not( selector ).fadeIn(800);
// $( selector ).fadeOut(800);
// $('#products img').not(selector).slideDown();
// $(selector).slideUp();
}