Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change the button name

I have a button, it consists of a name and an icon. I want to dynamically change the name of the button, but do not touch the icon. How can I do it? innerHTML innerText change completely, they don’t fit

<button>
   NameButton
    <svg>
    </svg>
</button>
like image 711
Michael George Avatar asked Aug 17 '26 12:08

Michael George


1 Answers

You can wrap text into span tag and use childNode to change

document.querySelector("button").childNodes[1].textContent="Something"
<button>
   <span>NameButton</span>
    <svg>
    
    </svg>
</button>

or Without Wrapping into span

document.querySelector("button").childNodes[0].textContent="Something2"
<button>
   NameButton
    <svg>
    
    </svg>
</button>
like image 105
Shubh Avatar answered Aug 19 '26 00:08

Shubh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!