1

I have been using document.write to open up this link i am creating in a new window.

document.write("<a target='blank' href='#"+link_number+"'>Click Here to open link</a>");

link_number is a dynamic number I am creating( it is different every time ). Now I am trying to put that link in to my table which is

<div id="tabs-10"> 
<table style="width:300px">
<tr><td><input type="button" id="Link1" checked /> Go to Link 1</td></tr>
</table>
</div> 

I know how to create a button such as How to create an HTML button that acts like a link?

But my question is, how can I convert my document.write into a button in my table?

Thank you Howard

Community
  • 1
  • 1

1 Answers1

0

You mean something like this?

var addButton = function(text) {
  var btn = document.createElement('button');
  var ttd = document.querySelectorAll('td')[0];

  btn.innerHTML = text;

  ttd.appendChild(btn);
}

document.querySelectorAll('a')[0].onclick = function() {
  addButton('Random ' + Math.random());
}
<div id="tabs-10"> 
  <table style="width:300px">
    <tr>
      <td>
        
      </td>
    </tr>
  </table>
</div>
<a>Add button</a>