MediaWiki:Common.js: Difference between revisions

From softwear.directory
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 all elements with class "card"
     // Get the element with id "list"
     var cards = document.querySelectorAll('.card');
     var list = document.getElementById('list');


     // Attach click event listener to each card
     // Check if the "list" element exists
    cards.forEach(function(card) {
    if (list) {
        card.addEventListener('click', function() {
        // Get all elements with class "card" within the "list" element
            // Log a message to the console when a card is clicked
        var cards = list.querySelectorAll('.card');
            console.log('Card clicked!');
 
        // 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.');
    }
});