MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
// Wait for the DOM to be ready | // Wait for the DOM to be ready | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
// Get | // Get the element with id "list" | ||
var | var list = document.getElementById('list'); | ||
// Attach click event listener to each card | // Check if the "list" element exists | ||
if (list) { | |||
// Get all elements with class "card" within the "list" element | |||
var cards = list.querySelectorAll('.card'); | |||
// Attach click event listener to each card | |||
cards.forEach(function(card) { | |||
card.addEventListener('click', function() { | |||
// Log a message to the console when a card is clicked | |||
console.log('Card clicked!'); | |||
}); | |||
}); | }); | ||
}); | } else { | ||
console.error('Element with id "list" not found.'); | |||
} | |||
}); | }); |
Revision as of 10:56, 8 January 2024
// Wait for the DOM to be ready document.addEventListener('DOMContentLoaded', function() { // Get the element with id "list" var list = document.getElementById('list'); // Check if the "list" element exists if (list) { // Get all elements with class "card" within the "list" element var cards = list.querySelectorAll('.card'); // Attach click event listener to each card cards.forEach(function(card) { card.addEventListener('click', function() { // Log a message to the console when a card is clicked console.log('Card clicked!'); }); }); } else { console.error('Element with id "list" not found.'); } });