QNA > H > How To Change A Text Button In Jquery

How to change a text button in jQuery

For buttons created with .Button() in jQuery........

Simply put, you can also try something like this:

  1. Button Name  

And in your jquery code usually wrapped in Javascript, you can do something like:

  1. $("#mytxt").text("New Button Value"); 
  2.  

Whilst the other answers will change the text they will mess up the styling of the button, it turns out that when a jQuery button is rendered the text of the button is nested within a span e.g.

  1.  
  2. My Text 
  3.  

If you remove the span and replace it with text (as in the other examples) - you'll loose the span and associated formatting.

So you actually need to change the text within the SPAN tag and NOT the BUTTON!

  1. $("#thebutton span").text("My NEW Text"); 

or (if like me it's being done on a click event)

  1. $("span", this).text("My NEW Text"); 

Di Viehmann

Perché Apple non può rilasciare un telefono con una fotocamera da 48MP come Xiaomi (marchio cinese)? :: Come cambiare i font in Windows 10
Link utili