JavaScript How to Print A Label in a DIV?

I have 4 boxes labeled a1, a2, a3, a4 as an example. And when someone clicks on 2 boxes, I want the label (a1, a2 as an example) to print on html output. I just spent over an hour and the best I can come up was printing undefined and null.

Sorry, here is my code

HTML
<div class="container">
  <div class="row">
    <div class="col-md-3" label="a1">
      <a class="btn btn-primary" href="#" role="button">Button 01</a>
      <div class="output"></div>
    </div>
    <div class="col-md-3" label="a2">
      <a class="btn btn-primary" href="#" role="button">Button 02</a>
      <div class="output"></div>
    </div>
    <div class="col-md-3" label="a3">
      <a class="btn btn-primary" href="#" role="button">Button 03</a>
      <div class="output"></div>
    </div>
    <div class="col-md-3" label="a4">
      <a class="btn btn-primary" href="#" role="button">Button 04</a>
      <div class="output"></div>
    </div>
  </div>
</div>
const button = document.querySelector('.btn');

button.addEventListener('click', printLabel);

function printLabel(){
  const name = document.querySelector('label');
  const print = document.querySelector('.output');
  print.innerText = name;
}

213 thoughts on “JavaScript How to Print A Label in a DIV?”

  1. Hi there! I understand this is kind of off-topic however I had to ask.
    Does running a well-established website such as yours require a lot of work?
    I am brand new to operating a blog but I do write in my journal
    on a daily basis. I’d like to start a blog so I will be able to share
    my own experience and views online. Please let
    me know if you have any kind of ideas or tips for new aspiring bloggers.
    Appreciate it! https://herreramedical.org/hydroxychloroquine

    Reply
  2. Pingback: med priligy
  3. Pingback: sildenafil 50 mg
  4. Pingback: generic viagra
  5. Pingback: sale cialis
  6. Pingback: sildenafil viagra
  7. Pingback: viagra coupon
  8. Pingback: deltasone 100mg
  9. Pingback: online viagra soft
  10. Pingback: tadalafil generico
  11. Pingback: viagra on the web
  12. Pingback: cialis coupon
  13. Pingback: natural viagra\
  14. Pingback: sildenafil coupon
  15. Pingback: online viagra
  16. Pingback: 100 viagra pill
  17. Pingback: viagra tablets uk
  18. Pingback: red viagra tablets
  19. Pingback: female viagra pill
  20. Pingback: viagra otc
  21. Pingback: cost for viagra
  22. Pingback: women take viagra
  23. Pingback: viagra amazon
  24. Pingback: women viagra
  25. Pingback: viagra online
  26. Pingback: viagra or cialis
  27. Pingback: viagra usa
  28. Pingback: buy liquid cialis

Leave a Comment