for(var i = 0; i < checkeds.length; i++){ var check = 'user'+checkeds[i]+'--mycheckbox'; $("#"+check).parent('td').siblings('.text-status').removeClass('text-green'); console.log($("#"+check).parent('td')); }
In this code, checkeds is an array of ids. The third line is to find elements with the .text-status style in the sibling elements of the parent of the id element and remove the text-green style.
But it cannot take effect. The following is the content of the parent element td reported by the console;
[prevObject: n.fn.init, context: document] context : document length : 0 prevObject : n.fn.init __proto__ : Object(0)
This is the hierarchical relationship of HTML
0001 耿直BOY 男 1990-02-01 曾经获得迪尼斯全球最能吃奖曾经获得迪尼斯全球最能吃奖 北京 2399 123 github ****** 18511009922 1991-02-01 23 23 23 正常
Just open the simplest demo and try it out, you will know, it can be spliced,
I can only say where is the problem with the code on your page
Look at the id in the html as user1-mycheckbox
Looking at your splicing, it is 'user'+checkeds[i]+'--mycheckbox';
One is a dash, the other is a double dash, or is the code posted wrong?
The questioner can judge whether the selector is normal
// check = user1--mycheckbox
It can be used. If it cannot be used, it can only be because the ID does not exist on your page
Can the questioner please send me the test code? This situation usually means that you have not found the right level
Check the output to see if it is the result you want. If so, check again whether the id exists on the page. The element with this id must also exist on the page at the beginning and cannot be a future element! Future elements need to use event delegation.