“Counter in JavaScript” Kode Jawaban

Counter in JavaScript

## MY HTML
<button id='counter'>Click Me To Count</button>
<span id='result'>1</span>

## MY JAVASCRIPT
let counter = document.getElementById("counter")
let result = document.getElementById("result")
let count = 1

counter.addEventListener("click", () => {
  count += 1
  result.innerHTML = count
})
Nar

Hitung JavaScript

const collect = require('collect.js');

const collection = collect([1, 2, 3, 4]);
const x = collection.count();
  
console.log(`Total number of elements are : ${x}`);
// Output: Total number of elements are : 4
Undefined

Counter JavaScript

//simple counter in javascript 

// this is button element variable
const button = document.querySelectorAll(".btn")

//this variable for display counter number
const h3 = document.querySelector(".counter")
//Count variable
let count = 0;

//foreach method
button.forEach((btn) => {
  //event listener function       
  btn.addEventListener("click", (e) => {
    //event targeting element  
    let target = e.currentTarget

    //condition for counter variable
    if (target.innerText == "reset") {
      count = 0;
    }
    else if (target.innerText == "next") {
      count++;
    }
    else if (target.innerText == "prev") {
      count--;
    }
    //text contains according to the if condition
    h3.innerHTML = count;

  })

})









SkiLL3r

Counter di HTML dan JS

<!-- HTML ->
<button id="btn-count">Count</button>
<p id="result"></p>

// JavaScript
const btnCount = document.getElementById('btn-count');

btnCount.addEventListener('click', () => {
  	let counter = 0;
  	counter++;
  	document.getElementById('result').innerText = counter;
});
Whale

JS Peningkatan Nilai Keselamatan HTML

function addRow(tableID) {

        var table = document.getElementById(tableID);

        var rowCount = document.getElementById(tableID).getElementsByTagName('tbody')
        [1].getElementsByTagName('tr').length;
        var row = table.insertRow(rowCount +1);

        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "hidden";
        element1.name = "Q[]";
        element1.value = rowCount +1;
        cell2.appendChild(element1);
        cell2.innerHTML = rowCount +1;
}

function deleteRow(tableID) {
        try {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;

        for(var i=0; i<rowCount; i++) {
            var row = table.rows[i];
            var chkbox = row.cells[0].childNodes[0];
            if(null != chkbox && true == chkbox.checked) {
                table.deleteRow(i);
                rowCount--;
                i--;
            }


        }
        }catch(e) {
            alert(e);
        }
}
KillberkCoding

Jawaban yang mirip dengan “Counter in JavaScript”

Pertanyaan yang mirip dengan “Counter in JavaScript”

Lebih banyak jawaban terkait untuk “Counter in JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya