change span text inside a button tag in jquery

10,228

Solution 1

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

Live Demo

$('button.myBtn.myBtnCTA.signIn span').text()

Solution 2

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

Beware that this selector may be inefficient.

Solution 3

This should work

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

Working demo

Solution 4

try this code

$(".myBtn.myBtnCTA.signIn span").text("text");
Share:
10,228
ACP
Author by

ACP

Updated on June 15, 2022

Comments

  • ACP
    ACP almost 2 years

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