Search code examples
javascriptjquerycopydata-class

Copy input into different cells with jQuery and data-class


Multiple tables contain data in cells. If I change the data in a cell, they should also be changed in the same cell in other tables.

<table id="1"><tr><td data-class="row1_col1"><input...></td><td data-class="row1_col2"><input...></td>...<td data-class="rowx_coly"><input...></td></tr></table>

var dataClass   = $(this).data("class");
var dataChk     = this.checked;
$("[data-class]").each(function(){
    if( $(this).attr("data-class") == dataClass){
        do the magic:-)
    }   
});

But these solution is very slowly for big datas.

Is there a other way like:

$(this).data("class", dataClass ).each(function(){
    do the magic :-)
});

or a other solution? Best thanks for helping


Solution

  • $("[data-class='" + dataClass + "']").each(function(){ 
        // Do magic!
    });
    

    DataClass is a variable. It works great also with big data sets.