Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javscript foreach with click listener

var postBoxes = document.querySelectorAll('.post-box')
postBoxes.forEach(function(postBox) {

  postBox.addEventListener('click', function() {
    var postId = this.getAttribute('post-id')
  console.log(postId)
    document.getElementById('comment-form-' + postId).style.display = 'block'
  })
})
Comment

js addeventlistener foreach

var buttons = document.querySelectorAll('.btn-click-me');
for (var i = 0; i < buttons.length; i++) {
    var self = buttons[i];

    self.addEventListener('click', function (event) {  
        // prevent browser's default action
        event.preventDefault();

        // call your awesome function here
        MyAwesomeFunction(this); // 'this' refers to the current button on for loop
    }, false);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to validate a string using regular expression in javascript 
Javascript :: axios get status code 
Javascript :: jquery input value change event not working 
Javascript :: nuxt-link name params 
Javascript :: get number from string using jquery 
Javascript :: get month in two digit in javascript date 
Javascript :: unable to open file in target xcode react native 
Javascript :: jquery see if checkbox is checked 
Javascript :: jquery remove child 1 elemtn 
Javascript :: how to test on user reaction discord.js 
Javascript :: vue get element height 
Javascript :: import all images from folder reactjs 
Javascript :: javascript write all the prime numbers from 1 to 100 
Javascript :: how to make a show password button 
Javascript :: javascript iterate over object keys and values 
Javascript :: data table 
Javascript :: How to fix WordPress jQuery is not defined 
Javascript :: react-router 
Javascript :: timestamp to date javascript 
Javascript :: how to convert string to lowercase in javascript 
Javascript :: js toggle value 
Javascript :: Unable to locate package node 
Javascript :: ejs variable 
Javascript :: node js cron example 
Javascript :: any click event jquery 
Javascript :: Codewars JS Multiples of 3 or 5 
Javascript :: how to find whether empty or not using jQuery 
Javascript :: javascript find all odd between two numbers 
Javascript :: how to make a deep copy in javascript 
Javascript :: javascript countdown timer 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =