Remove row from jquery row

Ignore my newcomers to jquery. I began to study recently, and I have a challenge in front of me. I have a checkbox with the names checkbox_0, checkbox_1 and you want to remove "checkbox_" from the rows so that I use 0, 1 in my loop to retrieve the data for this index. Thanks

The aData value tells me the value of checkbox_0, checkbox_1, etc. these checkboxes are selected.

submitButton.on("click", function() { $("Table :checked").each(function(e) { var iData =Table.fnGetData( this.parentNode); // Strip of the checkbox_ from the string for(var i=0; i<=iData.length; i++) { aData = iData[i][7]; } alert(aData); Table.fnDraw(); }); }); 
+7
source share
4 answers

This is just JavaScript, not jQuery.

To remove the first appearance of the work "checkbox _":

 var updatedString = originalString.replace("checkbox_", ""); 

Or, if you know that it will always be in the form of "checkbox_n" , where n is a digit,

 var updatedString = originalString.substring(9); 

... which discards the first nine characters from the string.

In any case, you will get a string. If you want a number, you can use parseInt :

 var updatedString = parseInt(originalString.replace("checkbox_", ""), 10); // or var updatedString = parseInt(originalString.substring(9), 10); 

... or just put a + in front of it to trigger an automatic cast (but note that in this case both decimal and hexadecimal strings will be processed):

 var updatedString = +originalString.replace("checkbox_", ""); // or var updatedString = +originalString.substring(9); 

Notice that I wrote updatedString = originalString.blah(...); but, of course, you can replace your link, for example, "originalString = originalString.blah (...);`.

More details:

+31
source
 submitButton.on("click", function() { $("Table :checked").each(function(e) { var iData =Table.fnGetData( this.parentNode); // Strip of the checkbox_ from the string for(var i=0; i<=iData.length; i++) { aData = iData[i].replace("checkbox_", ""); } alert(aData); Table.fnDraw(); }); }); 
+3
source

To remove the checkbox_ part, you can simply do this:

 cbName=cbName.replace("checkbox_", ""); 

To do this for all of your .each() inside the .each() loop:

 var cbIndex=this.name.replace("checkbox_", ""); //or... var cbIndex=this.name.split("checkbox_").join(""); 
+1
source

There are many ways to do this, some of them:

 $("table :checked").each(function() { var theNumber = this.name.replace(/\D/g, ""); var theNumber = this.name.replace(/[^\d]/g, ""); // or this var theNumber = this.name.match(/\d/g).join(); // or this 
+1
source

All Articles