Search code examples
javascripthtmltags

How to add html text inside tag?


I am wondering how I can add html text inside tag using javascript. Not class or id that can be added with classList.add('') or setAttribute. For example, I want to add html text 'disabled' inside the button tag like this: <button class="button is-danger" id="reset">Reset</button> to <button class="button is-danger" id="reset" **disabled**>Reset</button>

What would be the code for javascript? Thank you very much in advance

Edit: Disabled is an attribute


Solution

  • Disabled too is an attribute. Just writing disabled is the same as defaulting it to true.disabled

    If you want to add a custom attribute to pick you can and should refer to data attributes here:custom attributes

    As an example, you can add these attributes via simple dom-manipulation using setAttribute itself.setting an attribute