DeveloperBreeze

JavaScript Add Animation to HTML Element

// Get the HTML element by its ID
const animatedElement = document.getElementById('animatedElement');

// Add animation classes to the element using classList
animatedElement.classList.add('animate__animated', 'animate__bounce');

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
php

Exporting Table Row Data to CSV in JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Export Table Row to CSV</title>
</head>
<body>

<table>
    <tr>
        <td>Apple</td>
        <td>Banana</td>
        <td>Cherry</td>
        <td><a class="export-btn">Export</a></td>
    </tr>
    <tr>
        <td>Dog</td>
        <td>Cat</td>
        <td>Bird</td>
        <td><a class="export-btn">Export</a></td>
    </tr>
</table>

<script>
    // Select all export buttons
    const exportButtons = document.querySelectorAll('.export-btn');

    // Add event listener to each export button
    exportButtons.forEach(button => {
        button.addEventListener('click', () => {
            // Get the parent row of the clicked button
            const row = button.closest('tr');

            // Get all cells in the row except the last one (which contains the export button)
            const cells = Array.from(row.querySelectorAll('td'));
            cells.pop(); // Remove the last cell (the button cell)

            // Extract the text content of each cell and wrap them in double quotes (CSV format)
            const cellValues = cells.map(cell => `"${cell.textContent}"`);

            // Create the CSV data by joining cell values with commas
            const csvData = cellValues.join(',');

            // Create a temporary anchor element for the download
            const anchor = document.createElement('a');
            anchor.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csvData);
            anchor.download = 'row_data.csv';

            // Programmatically click the anchor to trigger the download
            anchor.click();
        });
    });
</script>

</body>
</html>

In this tutorial, we’ve learned how to export individual table rows as CSV files using plain JavaScript. By attaching event listeners to "Export" buttons within each row, we were able to dynamically generate CSV files based on the data in each row. This functionality can be especially useful in applications where users need to download specific data sets for further analysis.

Oct 24, 2024
Read More
Tutorial
javascript

Easy JavaScript Tutorial for Beginners

let result = 5 + 3;  // 8
  • ==: Equal to
  • ===: Strict equal to (checks value and type)
  • !=: Not equal to
  • >, <: Greater than, less than

Sep 18, 2024
Read More
Tutorial
javascript

MDN's In-Depth JavaScript Guide: A Comprehensive Resource for Developers

MDN’s guide also covers different programming paradigms that can be used in JavaScript:

  • Object-Oriented Programming (OOP): Concepts such as classes, inheritance, and prototypes.
  • Functional Programming: Introduction to higher-order functions, pure functions, and immutability.
  • Asynchronous Programming: Detailed coverage of callbacks, promises, async/await, and event loops.

Aug 30, 2024
Read More
Tutorial
javascript

Understanding the DOM in JavaScript: A Comprehensive Guide

function handleClick() {
    alert('Button was clicked!');
}

button.addEventListener('click', handleClick);

// Later in the code...
button.removeEventListener('click', handleClick);

The DOM provides methods to navigate between nodes, which is useful for finding related elements.

Aug 30, 2024
Read More
Code
javascript json

JavaScript Code Snippet: Fetch and Display Data from an API

No preview available for this content.

Aug 04, 2024
Read More
Note
javascript css +1

Automatically add Tailwind CSS and jQuery classes to any table

  • bg-gray-50: Light gray header background.
  • px-6 py-3: Padding.
  • text-left text-xs font-medium text-gray-500 uppercase tracking-wider: Header text styling.
  • border-b border-gray-200: Bottom border.

Aug 03, 2024
Read More
Code
javascript

Password Toggle

// Get references to the password input and toggle button
const passwordInput = document.getElementById('passwordInput');
const toggleButton = document.getElementById('toggleButton');

// Add event listener to the toggle button
toggleButton.addEventListener('click', () => {
    // Toggle the password input type between 'password' and 'text'
    passwordInput.type = passwordInput.type === 'password' ? 'text' : 'password';
});

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!