How to remove prefix in jquery .?
<td><span id="stu1" class="reject-student ">Not Selected</span></td>
<td><span id="stu2" class="select-student ">Selected</span></td>
<td><span id="stu5" class="select-student ">Selected</span></td>
jquery:
var selected = $(".select-student").map(function() {
return this.id;
}).get();
i have trid like this:
var selected = $(".select-student").map(function() {
var id = $('span[id^="stu"]').remove();
return this.id;
}).get();
I am getting result like stu1 stu2 i want to send only 1 and 2.. how can i do that.?
You don't need $('span[id^="stu"]').remove(); the statement with remove element.
A simple solution is to use the String.prototype.replace() method to replace stu
var selected = $(".select-student").map(function() {
return this.id.replace('stu', '');
}).get();
Additionally, you can also use RegEx to remove all non numeric characters
var selected = $(".select-student").map(function() {
return this.id.replace (/[^\d]/g, '');
}).get();
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