Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to do it would be using <code>document.createElement</code></p> <p>Instead of doing:</p> <pre><code>yourParentElement.innerHTML = "&lt;tr&gt;Something&lt;/tr&gt;"; </code></pre> <p>You can do</p> <pre><code>var tr = document.createElement("tr"); tr.innerHTML = "Something"; tr.onclick = function() { //code to be executed onclick }; yourParentElement.appendChild(tr); </code></pre> <p>Another way, would be to use an <code>id</code> (<strong>only</strong> if you're doing this once, you don't want duplicated ids):</p> <pre><code>yourParentElement.innerHTML = "&lt;tr id='someId'&gt;Something&lt;/tr&gt;"; document.getElementById("someId").onclick = function() { //fetch the element and set the event } </code></pre> <p>You can read more about events <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event" rel="nofollow">here</a>, but just so you have an idea <code>onclick</code> will only let you set <em>one</em> function. If you want a better solution you can use something like <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener" rel="nofollow">addEventListener</a>, but it's not <a href="http://en.wikipedia.org/wiki/Cross-browser" rel="nofollow">crossbrowser</a> so you may want to read up on it.</p> <p>Lastly, if you want to set up an event on <em>every</em> <code>tr</code> you can use:</p> <pre><code>var trs = document.getElementByTagName("tr"); //this returns an array of trs //loop through the tr array and set the event </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload