I've got a string that has data-123
as its value. How in jQuery
or Javascript
would I go in and remove the data-
from the string while leaving the 123
?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
No jQuery needed.
Docs.
For all occurrences to be discarded use:
PS: The replace function returns a new string and leaves the original string unchanged, so use the function return value after the replace() call.
you can use slice() it returens charcters between start to end (included end point)
here is some exmp to show how it works:
Demo
I was used to the C# (Sharp) String.Remove method. In Javascript, there is no remove function for string, but there is substr function. You can use the substr function once or twice to remove characters from string. You can make the following function to remove characters at start index to the end of string, just like the c# method first overload String.Remove(int startIndex):
and/or you also can make the following function to remove characters at start index and count, just like the c# method second overload String.Remove(int startIndex, int count):
and then you can use these two functions or one of them for your needs!
Example:
Output: 123
This little function I made has always worked for me :)
I know it is not the best, but It has always worked for me :)