okan s
okan s

Reputation: 3

jquery- How to get the list item id of the parent and the position of an li item

i would like to access li (id-67) via li (id-68)

i tried $("#68").parent('li').attr("id") and $("#68").parent().parent('li').attr("id")

and could not grab the id 67.. Any idea thanks!

enter image description here

Upvotes: 0

Views: 396

Answers (2)

Avaq
Avaq

Reputation: 3031

You could use jQuery.fn.parents() to get to the closest parent li:

$('#68').parents('li:eq(0)').attr('id');

Upvotes: 1

TwTw
TwTw

Reputation: 547

You could use jQuery.fn.prev() :

$("#68").prev();

Upvotes: 0

Related Questions