Jquery - selecting parents with a data attribute

I am trying to select a parent which HAS an attribute of datalink

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

Is this possible?

1 answer

  • answered 2017-09-19 11:50 Utkanos

    Yes

    .parents('[data-link]') //<-- string denoting attribute
    

    not

    .parents(['data-link']) //<-- array containing string