KodeFor.Me
KodeFor.Me

Reputation: 13511

jQuery | String replace does not work

I have the following script:

var id = $(this).attr('id');
var ui_id = id.replace("delete", "hidden");
var am_id = id.replace("delete", "internal");

If I do

console.log(id);

I get the following value:

widget-zcircle-2-link_image-remove

But the values of ui_id and am_id are not changing.

The following code :

console.log(ui_id);
console.log(am_id);

print out in my console the following result:

widget-zcircle-2-link_image-remove
widget-zcircle-2-link_image-remove

instead of

widget-zcircle-2-link_image-hidden
widget-zcircle-2-link_image-internal

Is something wrong in my code that I cannot see ?

Kind regards Merianos Nikos

Upvotes: 0

Views: 453

Answers (2)

Talha
Talha

Reputation: 19272

Replace delete from remove in your replace function... just like

var ui_id = id.replace("remove", "hidden");

Upvotes: 4

Jon
Jon

Reputation: 437664

Your input contains "remove" but your code is looking for "delete".

Upvotes: 2

Related Questions