I’m really new to JavaScript.
I have a html like this:
<li><a class="dropdown-item confirm" href="#">wtdata</a></li>
How can I use js to click this link and get ‘wtdata’ ,then display the value ‘wtdata’ in here:
<h5 id="staticBackdropLabel">You want to run wtdata ?</h5>
3
Answers
I think you have to handle the click on the
a
to get the value of the tag, and then display it in yourh5
I prefer
querySelector
overgetElementsByClassname
, you don’t have to get the[0]
element withquerySelector
:https://developer.mozilla.org/fr/docs/Web/API/Document/querySelector
Add a
onClick
event to your<a/>
tag, then useinnerText
attribute. like this