Mustapha Aoussar
Mustapha Aoussar

Reputation: 5923

How to remove text from "/" to the end of the text?

I have this dynamic text pluto.co/bf4d4ce3-c2b9-4e77-8adb-925f5adf927a, I want to remove with jquery the code between slash and the end of text.

I tried with the following:

var div = $("div.text");
div.text(div.text().trim().replace("/bf4d4ce3-c2b9-4e77-8adb-925f5adf927a", ""));

But doesn't work because the text changes when I refresh the page.

Upvotes: 0

Views: 43

Answers (2)

Naramsim
Naramsim

Reputation: 8732

Use. Split() then remove the last part of array

Upvotes: 0

antyrat
antyrat

Reputation: 27765

You can do this without regex:

var tmpString = div.text().trim().split('/');
tmpString.pop();
div.text(tmpString.join(''));

Upvotes: 1

Related Questions