Reputation: 1862
I have a lot of links I have to modify. I have to replace each url of them with a hardcoded link.
For example path/to/something.html?L
into this/is/the/right/path.html?L
Everything until ?L
has to be replaced. Everything in first path until the ?L
parameter is dynamic.
How could I do this?
Upvotes: 1
Views: 150
Reputation: 148180
You can do it this way,
prev = $('a[href^=path/to/something.html]').attr('href')
required = prev.split('?')[1];
$('a[href^=path/to/something.html]').attr('href', 'this/is/the/right/path.html?' + required);
Upvotes: 3
Reputation: 7603
try this
$('a[href="path/to/something.html?L"]').attr('href', 'this/is/the/right/path.html?L')
Basically what it says is to find all the links with a certain href and replace the href with the new one.
Is L a constant or is it just for an example and L can be multiple things?
Upvotes: 1