click on a link and display an html code in a textarea

Asked

Viewed 47 times

0

how I would do for when I click on a certain link for example <a href='javascript:void(0)'>Capitulo</a> display in a textarea the tags <strong></strong>, among other link’s that I’ll have to display different tags

document.addEventListener("DOMContentLoaded", function() {
  var els = document.body.querySelectorAll("a[href*='java']");
  for (var x = 0; x < els.length; x++) {
    els[x].addEventListener("click", function() {
      var a_txt = this.textContent,
        inpt = document.body.querySelector("#versiculos");
      inpt.value += " " + a_txt;
    });
  }
});
<ul>
  <li><a href="javascript:void(0)">Capitulo</a></li>
  <li><a href="javascript:void(0)">Versículo</a></li>
  <li><a href="javascript:void(0)">Destaque</a></li>
  <li><a href="javascript:void(0)">Link's</a></li>
  <li><a href="javascript:void(0)">Quebra de linhas</a></li>
</ul>
  • you’ll have to give more context (html and explanation) so you can understand what you want to do

  • when clicking on Chapter, it prints in a textarea the tags <Strong></Strong> , and so for each link, each link corresponds to a different tag

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.