tags:

views:

154

answers:

1

this code below selects all the given children from the parent.

$(this).parent().find(this.attr("tagName").toLowerCase())

however, i dont know how to traverse upwards with the parent(). i would require a function that would automatically keep adding .parent() each time the function is called.

For example, i call function once and it returns $(this).parent().find(this.attr("tagName").toLowerCase())

I call the function for second time again and it returns $(this).parent().parent().find(this.attr("tagName").toLowerCase())

Third time, $(this).parent().parent().parent().find(this.attr("tagName").toLowerCase())

+1  A: 
$('p:eq(0)').parents().each(function() {
    var el = $(this).find( $(this).attr('tagName').toLowerCase() );
    if ( el.length ) {
        console.log(el);
    }
});
meder
im not sure what this does....but what i meant was call a function which will return $(this).parent().find(this.attr("tagName").toLowerCase()). call it again and it will return $(this).parent().parent().find(this.attr("tagName").toLowerCase())
gorbachev
Well, if you have Firebug you can copy my code paste it in and pretty much see what it does, but it basically loops through all the parent elements of the initial node and finds similar node name descendants and logs them, you can do what you want with the `el` variable.
meder
did this answer your question?
meder