Reputation: 39
I want to remove the last parameter in the href of a specific tag using jquery
for example replace href="app/controller/action/05/04/2014"
by href="app/controller/action/05/04"
Upvotes: 2
Views: 310
Reputation: 1600
We can use a regular expression replace which will be the fastest, compared to substring/slice.
var hreftxt ="app/controller/action/05/04/2014";
hreftxt = hreftxt.replace(/\/[^\/]*$/,"");
Upvotes: 0
Reputation: 6925
if you know which value you need to change ,than you can use replace:
var str = "app/controller/action/05/04/2014";
var res = str.replace("2014","04");
or else you can use array and change / update last value in array:
var str = "app/controller/action/05/04/2014";
var res = str.split("/");
Upvotes: 0
Reputation: 67207
Try using the String.lastIndexOf()
and String.substring()
in this context to achieve what you want,
var xText ="app/controller/action/05/04/2014";
xText = xText.substring(0,xText.lastIndexOf('/'));
Upvotes: 3