简体   繁体   中英

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

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

Live Demo

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

请注意,此选择器可能效率低下。

This should work

$(".myBtn.myBtnCTA.signIn>span").text("Save & Close");

Working demo

试试这段代码

$(".myBtn.myBtnCTA.signIn span").text("text");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM