Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select first block level parent with jQuery?

Consider the following markup:

<div id="0">
    <h1 id="1">
        <span id="2"><span id="3">lorem ipsum</span></span>
    </h1>
</div>

How can I find the first parent of span#3 that is of block level (i.e. has display: block) using jQuery? In this case that would be h1#1.

like image 702
sbichenko Avatar asked Dec 20 '11 13:12

sbichenko


1 Answers

$("#3").parents().filter(function() {
    return $(this).css("display") === "block";
}).first()

http://jsfiddle.net/DFURw/

like image 188
Esailija Avatar answered Oct 07 '22 09:10

Esailija