insert values inside table using javascript

-1

I need to create a input within a cell of a table using JavaScript. I created a <a> tag with name="ex2"

<tr><p>
<td id="secTd"><label for="cAp"><a id="num">02</a> <a id="texto">Time</a></label></td>
<td id="tecTd"><a name="ex2"></a></td>
</p></tr>

And I'm using this JavaScript code to write "val1" inside this tag.

document.getElementById("exibe1").innerHTML = "val1";

No error message appears, same thing if I try with a input .

    
asked by anonymous 05.04.2017 / 22:13

1 answer

1

If I understand correctly, the only problem is to search with JavaScript for an element whose id is exibe1 while the desired element or id is set. You can then properly set the property on the element or do:

document.querySelector("a[name='ex2']").innerHTML = "val1";
<tr>
  <p>
    <td id="secTd"><label for="cAp"><a id="num">02</a> <a id="texto">Time</a></label></td>
    <td id="tecTd">
      <a name="ex2"></a>
    </td>
  </p>
</tr>
  

This p element defined within tr does not seem to make sense.

    
06.04.2017 / 02:30