Jquery - 选择具有数据属性的父项

时间:2017-09-19 11:50:49

标签: jquery jquery-selectors custom-data-attribute parents

我正在尝试选择具有datalink属性的父级

var url = $(e.target).parents(['data-link']).addClass('selected');

这可能吗?

1 个答案:

答案 0 :(得分:1)

Sub Demo()
    Dim lastRow As Long
    Dim cel As Range

    With Worksheets("Sheet3")   'change Sheet3 to your data sheet
        lastRow = .Cells(.Rows.Count, "R").End(xlUp).Row    'get last row in Column R

        For Each cel In .Range("R5:R" & lastRow)    'loop through each cell in range R5 to lase cell in Column R
            If cel.Value = "invalid" And Not IsEmpty(cel.Offset(0, 1)) And Not IsEmpty(cel.Offset(0, 2)) Then
                cel.EntireRow.Hidden = True 'hide row if condition is satisfied
            End If
        Next cel
    End With
End Sub

Sub UnhideRows()
    Worksheets("Sheet3").Rows.Hidden = False
End Sub