DeveloperBreeze

Html Programming Tutorials, Guides & Best Practices

Explore 5+ expertly crafted html tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Tutorial
php

Creating a Countdown Timer with JavaScript

Next, we need a function to update the timer every second:

function initializeClock(id, endtime) {
    const clock = document.getElementById(id);
    const daysSpan = clock.querySelector('.days');
    const hoursSpan = clock.querySelector('.hours');
    const minutesSpan = clock.querySelector('.minutes');
    const secondsSpan = clock.querySelector('.seconds');

    function updateClock() {
        const t = getTimeRemaining(endtime);

        daysSpan.innerHTML = t.days;
        hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
        minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
        secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);

        if (t.total <= 0) {
            clearInterval(timeinterval);
        }
    }

    updateClock();
    const timeinterval = setInterval(updateClock, 1000);
}

Oct 24, 2024
Read More
Tutorial
php

Exporting Table Row Data to CSV in JavaScript

// 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();
    });
});
  • querySelectorAll('.export-btn'): Selects all elements with the class export-btn, i.e., the export buttons.
  • closest('tr'): This retrieves the closest table row (<tr>) that contains the clicked button.
  • querySelectorAll('td'): Retrieves all the <td> cells in the row.
  • Array.from(): Converts the list of cells into an array, which allows us to manipulate it easily.
  • cells.pop(): Removes the last cell (the one containing the export button), as we don’t want it in the CSV.
  • textContent: Extracts the text content from each cell.
  • encodeURIComponent(): Encodes the CSV string, making it safe for use in a URL.
  • anchor.download: Specifies the filename for the CSV file (in this case, row_data.csv).
  • anchor.click(): Programmatically triggers a click on the anchor element, which starts the download.

Oct 24, 2024
Read More
Tutorial
javascript css +1

دليل شامل لتطوير الويب: بناء موقع بسيط باستخدام HTML, CSS وJavaScript

  • HTML: لهيكلة المحتوى.
  • CSS: لتنسيق التصميم.
  • JavaScript: لإضافة التفاعلات.

HTML هي لغة ترميز تساعدك في إنشاء الهيكل الأساسي لصفحة الويب. إليك الهيكل الأساسي لموقع ويب بسيط:

Sep 27, 2024
Read More
Cheatsheet
html

HTML5 Cheatsheet

  • <h1> to <h6>: Headings, with <h1> as the most important.
  • <p>: Paragraph.
  • <br>: Line break.
  • <hr>: Thematic break (horizontal rule).
  • <strong>: Important text (bold).
  • <em>: Emphasized text (italic).
  • <small>: Smaller text.
  • <mark>: Highlighted text.
  • <blockquote>: Long quotations.
  • <code>: Inline code.
  • <pre>: Preformatted text (preserves whitespace).

HTML supports ordered, unordered, and description lists:

Aug 03, 2024
Read More