A
A
Anton2021-07-03 22:18:14
JavaScript
Anton, 2021-07-03 22:18:14

How to execute such function on click of checkboxes?

Greetings, tell me how to register to perform this function only not by the button id, but by clicking on each checkbox on the page?

js jquery

$(document).on('click', '#button', function(){
  let txt = document.getElementById("keyPrivHex").value;
  $.ajax({
    url: 'test.php',
    type: 'POST',
    data: { txt: txt, },
    success: function(data){
     $('p.out').text(data);
   },
    error: function(){
  console.log('ERROR');
    }
 })
})

or in this way:
document.querySelectorAll("input[type='checkbox']").forEach(item=>{
item.addEventListener('click', func)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Vlasenko, 2021-07-03
@boypush

$(document).on('click', "input[type='checkbox']", function(){

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question