Search code examples
jqueryhtmldhtml

access outer element using jquery


I have an issue where I need to know what the outer li element is within the example here using jquery. Is this possible please?

http://jsfiddle.net/f5HHj/2/

Thanks, James


Solution

  • With the .parent() function you can get the parents of an HTML element, see my demo: http://jsfiddle.net/f5HHj/3/

    $('.Box a').click(function() {
        alert('You clicked a link in the ' + $(this).parent().parent().attr('class') + ' list item.');                                           
    })