Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change the value of span using Javascript or Jquery using <input> or text attribute

I want to change span value to <span class='tag'>test_succeed</span>,

I tried "input" but it doesn’t work, any idea ?

<span class="tag" id="tag-option">
  <input type='hidden' name='tag-value' value='' id="test-input">
  <span class="close"></span>
</span>
<script>
  document.getElementById('test-input').value = "test_succeed";
</script>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you are only trying to add text to the span, you don’t need an input element. You can use the innerText function.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText

<span class="tag" id="tag-option">
  <span class="close"></span>
</span>
<script>
  document.getElementById('tag-option').innerText = 'test_succeed';
</script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading