I’m trying to remove the text (in this example, it’s "Hi – "). But it’s not working.
<div class="custom-card-title">
<!-- Change to 1-1/32 HELLO -->
<a href="#">Hi - 1-1/32 HELLO</a>
</div>
let name = $('.custom-card-title a').text();
const newName = name.split(" - ").pop();
name = `${newName}`
3
Answers
You have to use
.html()
function to append the modified text to the anchor tag.You can use
.html()
or.text()
here to set the contents of an anchor element.html()
is used to return or change the inner html and text content of selected elements.text()
is used to return or change the text content of selected elements.