Question: Let's say I want that every time the user click any link an alert pops up that says "hohoho". 
Do I need to add `onclick="alert('hohoho')"` to every link or can I set this with CSS so that it works with every link?

Answer: 
Following JCOC611 suggestion:

```
window.onload = function() {    
    let elements = document.getElementsByClassName("someClassName");

    for(let i = 0; i < elements.length; i++) {
        elements[i].onclick = function () {
            alert("Clicked in an element of the class.");
        }
    }
};

```
Asking about "a class" in the question title, the answer is `getElementsByClassName`:

```
  var hrefs = document.getElementsByClassName("YOUR-CLASS-NAME-HERE");
  for (var i = 0; i < hrefs.length; i++) {
   hrefs.item(i).addEventListener('click', function(e){
    e.preventDefault(); /*use if you want to prevent the original link following action*/
    alert('hohoho');
   });
  }

```