Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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'
  })
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javscript #foreach #click #listener
ADD COMMENT
Topic
Name
4+5 =