Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change span text inside a button tag in jquery

I have html structure like this,

<button class="myBtn myBtnCTA signIn" onclick="javascript:;">
                            <span>Close</span>
</button>

I want to change the text from "Close" to "Save & Close". I tried this $(button .myBtn myBtnCTA signIn span).text() but this doesnt seem to work. Any suggestion??

like image 298
ACP Avatar asked Nov 24 '25 08:11

ACP


2 Answers

Use . dot to join multiple classes, also give selector in quotes.

Live Demo

$('button.myBtn.myBtnCTA.signIn span').text()
like image 98
Adil Avatar answered Nov 25 '25 22:11

Adil


$(".myBtn.myBtnCTA.signIn span").text("Hello world!");

Beware that this selector may be inefficient.

like image 43
gustavohenke Avatar answered Nov 25 '25 22:11

gustavohenke



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!