Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created April 8, 2014 08:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/10102663 to your computer and use it in GitHub Desktop.
Save troelskn/10102663 to your computer and use it in GitHub Desktop.
jquery - find closest data attribute.
var listId = $(this).parents().filter(function() { return $(this).data("list-id"); }).eq(0).data("list-id");
@let-aurn
Copy link

Thank you.
For those looking for a way to get the closest parent link with attribute, use

var listId = $(this).parents().filter(function() {
     return $(this).data("list-id");
}).eq(0);

Without .data("list-id"); at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment