How can I pass the onclick event flag to the parent onclick?

I a with the onclick event and, and inside it.
When I click on this flag, the div-onclick event does not fire - I would like it to fire without having to publish onclick on the flag.

<div id="id-tag" onclick="do()">
  <span>text</span>
  <img src="pic.jpg" />
  <input type="checkbox" name="mycheck" />
</div>

I know div-idtag, but ideally I would like to avoid specifying it inside the checkbox.
Using another function call in the onclick flag to call the parent is NOT what I'm looking for, for example

onclick="run_parent_onclick()"

but this is normal (untested)

onclick="this.parent.click()"
+3
source share
2 answers

You can fire the div click event manually on the onclick tab:

<input type="checkbox" name="mycheck" onclick="this.parentNode.click()" />

or

<input type="checkbox" name="mycheck" onclick="document.getElementById('id-tag').click()" />
+1
source

addEventListener:

function do(e) { ... }
document.getElementById('id-tag').addEventListener('click', do, true);

"" .

+1

Source: https://habr.com/ru/post/1743796/


All Articles