0

I'm trying to replace part of a string that contains specific text, I can't figure out what I'm missing. Can someone shed some light?

function trimUser() {
    var trimString = $('#selectedUsername').text();
    var trimmedString = "";
    trimmedString = $(trimString).text().replace(' - SupportUser', '');
    $(this).text(trimmedString);
    console.log(trimmedString);
}     
1
  • Change trimmedString = $(trimString).text().replace(' - SupportUser', ''); to trimmedString = trimString.replace(' - SupportUser', ''); Commented Oct 15, 2019 at 10:20

1 Answer 1

1

what i guess maybe your trimmedString = $(trimString).text().replace(' - SupportUser', ''); is mistake, you dont have element call $(trimString)

function trimUser() {
    var myelement = $('#selectedUsername');
    var trimString = myelement.text();
    var trimmedString = "";
    trimmedString = trimString.replace(' - SupportUser', '');
    myelement.text(trimmedString);
    console.log(trimmedString);
}     
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.