javascript - How to remove prefix in jquery id -


how 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 this:

var selected = $(".select-student").map(function() { var id = $('span[id^="stu"]').remove(); return this.id;  }).get(); 

i getting result stu1 stu2 want send 1 , 2.. how can that.?

you don't need $('span[id^="stu"]').remove(); statement remove element.

a simple solution use string.prototype.replace() method replace stu

var selected = $(".select-student").map(function() {    return this.id.replace('stu', '');  }).get(); 

additionally, can use regex remove non numeric characters

var selected = $(".select-student").map(function() {    return this.id.replace (/[^\d]/g, '');  }).get(); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -