找到最近/下一个div
我在
// first $row[11]
//second
这里是JQuery:
$(document).ready(function () { $('.date').each(function () { $('.question1').hide(); var date = new Date($(this).text().replace("-", "/")); var recstatus = $(this).closest('td').next().find('.recstatus'); if (new Date() > date && recstatus.text() == 3) { recstatus.addClass('invaliddate'); //if this is true then hide first div and show second div // something like this.. but this isn't working // i need closest/next div (this divs are in cycle) $(this).closest("div").find(".question1").show(); $(this).closest("div").find(".question").hide(); } }); });
我想显示question1 div if(这个jquery if语句是真的)并隐藏问题div但它们在循环中的
你需要找到父td
元素,然后找到你需要找到有问题的div的下一个兄弟td
$(this).closest("td").next().find(".question1").show(); $(this).closest("td").next().find(".question").hide();