0

How do can I remove the only text "You" from the string and only left the text "Kevin Yam, Bryan Ooi"

Output : Kevin Yam, Bryan Ooi

var panel = document.getElementById("panel" + (getlikeid));
var you = document.getElementById("only_you" + (getlikeid));

if (you.innerText === "You") {
  panel.remove();
} else if (you.innerText !== "You") {
  //execute code 
}
<span id="only_you11"> You, Kevin Yam, Bryan Ooi</span>

2
  • 1
    Please be specific what output you want. It will be like this Kevin Yam, Bryan Ooi Commented Jan 22, 2018 at 3:48
  • How to remove php flag? Commented Jan 22, 2018 at 3:48

2 Answers 2

1
  1. You .replace()

var  text1 = $('span').text().replace(/You,/g, '')
$('span').text(text1);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="only_you11"> You, Kevin Yam, Bryan Ooi</span>

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, but I don't know why the text() is not a function, so i change to --> var text1 = document.getElementById("only_you"+(getlikeid)).innerText.replace(/You,/g, ''); document.getElementById("only_you"+(getlikeid)).innerText = text1;
it is for jquery. i answered with jquery solution your solution will work because it is pure JS
0

Just JS...

    var you = document.getElementById("only_you11");
            you.innerHTML = you.innerText.replace("You,", "");

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.