Is it possible to put 2 onclick?

1

I currently have this

<li><a class="tablinks_ tab__active__" onclick="openCategory(event, '__IMAGEN1__1')">IMAGEN1</a></li>
<li><a class="tablinks_ tab__active__" onclick="openCategory(event, '__IMAGEN__2')">IMAGEN1</a></li>
<li><a class="tablinks_ tab__active__" onclick="openCategory(event, '__IMAGEN__3')">IMAGEN2</a></li>
<li><a class="tablinks_ tab__active__" onclick="openCategory(event, '__IMAGEN__4')">IMAGEN3</a></li>

And what I want to do is add another onclick to the <a> tags

    
asked by LorenaKING 21.04.2018 в 12:16
source

2 answers

2

For JavaScript you can do this:

onclick="hacerAlgo();hacerAlgoMas();"

But really, you'd better not use onclick to connect the event handler to the DOM node through your JavaScript code. This is known as discrete javascript .

Also, as you post @ track3r in your comment, you can do something like this:

A link with 1 defined function

<a href="#" onclick="tuFuncionDefinida()">Haz clic en mí para activar algunas funciones</a>

Shooting multiple functions from yourDefinedFunction ()

function tuFuncionDefinida() {
    mostrarAlert();
    validar();
    otraFuncion();
    otraFunctionMas();
}

See if it's good for you, Regards!

    
answered by 21.04.2018 в 14:45
-1

Look to see if it serves you. When you click on "IMAGE1", the two click events are executed: by id and by class.

<!DOCTYPE html>
<html>

<head>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>

<body>
  <script type="text/javascript">
    $(document).ready(function() {
      $("#click").click(function(event) {
        alert("click0");
      });
      $(".click1").click(function(event) {
        alert("click1");
      });
    });
  </script>
  <li><a class="tablinks_ tab__active__ click1" id="click">IMAGEN1</a></li>

</body>

</html>
    
answered by 21.04.2018 в 13:43