I am trying to make editable if the cell is filled. If it is not filled yet, it will not be editable.
I am using contenteditable but I can not select the td's all is fit my condition. When I try to write if, when one td is filled all td's are chosen. I tried to write if inside of foreach but I guess I can not do this because jquery selection doesnt return any array etc.
Do you have any suggestion ?
var edit3 = $('#table_mresults tbody tr').find(':nth-child(3)');
var edit4 = $('#table_mresults tbody tr').find(':nth-child(4)');
if(edit3 != "" && edit4 != ""){
edit3.attr('contenteditable','true');
edit4.attr('contenteditable','true');
}
var edit3 = $('#table tbody tr').find(':nth-child(3)');
var edit4 = $('#table tbody tr').find(':nth-child(4)');
edit3.forEach(e3 => {
if(e3 != "") e3.attr('contenteditable','true');
});
edit4.forEach(e4 => {
if(e4 != "") e4.attr('contenteditable','true');
});
edit: Solution Suggestion
Maybe I should try to give editable class for the filled rows and then selected with this class name ?
Try to check the element inner text NOT the element itself as in:
if(edit3.text().trim() != "" && edit4.text().trim() != ""){ edit3.attr('contenteditable','true'); edit4.attr('contenteditable','true'); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.