Dynamically change the button name

Michael George

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>
Shubh

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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related