I'm developing a small app, when a checkbox is checked it's id value is added to a hidden field, when unchecked, it's id has to be removed from the hiddenfield value. I know how to add, but don't know how to remove. It's like say there is a string strValue="abcde"; how do I remove 'c' from the strValue using jQuery? Thank you.
You can also remove a specified character or substring from a string by calling the String. Replace(String, String) method and specifying an empty string (String. Empty) as the replacement. The following example removes all commas from a string.
You can use replace.
strValue.replace('c', '');
Live Demo
I would suggest two things, looking at jQuerys .Data() method for storing values, and at the very least making your list delimited by something such as a comma.
Try this, make sure you take the result of replace method into a new string. It does not modify the original string.
var str = "somestring";
str = str.replace('some', 'someother');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With