Patrick Patrick - 1 year ago 111
jQuery Question

jQuery: selecting grandparents

Is there a better way to select grandparent elements in jQuery in order to avoid this ?

$(this).parent().parent().parent().parent().parent().children(".title, .meta").fadeIn("fast");


Answer Source

You can use the parents() method which matches parents against a selector

Or if you're using 1.4 there is a new parentsUntil() method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download