I have 4 cells. When you click on them, "Text 1" appears in each. I need that when clicking on the cell (c1), the cell (c2) “clicks”. That is, when clicking on (c1), a click on the cell (c2) simultaneously occurred. Thanks in advance for your help!

<head> <script> var current = "Text 1"; function onClick(sender) { if (sender.innerText == "") { sender.innerHTML = current; } } </script> </head> <body> <table border="1" cellpadding="50px;"> <tbody> <tr> <td id="c1" class="cell" onclick="onClick(this);"></td> <td id="c2" class="cell" onclick="onClick(this);"></td> </tr> <tr> <td id="c3" class="cell" onclick="onClick(this);"></td> <td id="c4" class="cell" onclick="onClick(this);"></td> </tr> </tbody> </table> </body> 
  • And when you click on c2 ? And when you click on c3 ? And when you click on c4 ? - Alexey Shimansky
  • I would like to consider only one example, after which I myself can prescribe what I need. - A.Hall
  • Just understand the thing in which, depending on the task, the logic will be different. for example, when you click c1 to click on c2 , it’s one thing, and if you’ve supposed to click on c2 so that c4 is clicked, that’s completely different. That is, you can make a decision based on the million ITUs that you assign to the cells, and you can make a decision based on a common line, or a common root in the form of a table - Alexey Shimansky
  • So far I need only when clicking c1 there was also a click on c2. - A.Hall

1 answer 1

 var current = "Text 1"; function onClick(sender) { if (sender.id == 'c1') $('#c2').click(); if (sender.innerText == ""){ sender.innerHTML = current; } } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table border="1" cellpadding="50px;"> <tbody> <tr> <td id="c1" class="cell" onclick="onClick(this);"></td> <td id="c2" class="cell" onclick="onClick(this);"></td> </tr> <tr> <td id="c3" class="cell" onclick="onClick(this);"></td> <td id="c4" class="cell" onclick="onClick(this);"></td> </tr> </tbody> </table> 

  • Yes, what you need! Thanks for the help! - A.Hall