How to choose parent level first level using jQuery?
4 answers
According to the W3C, a block level element may have a display of all content whose contents are treated as a table or block . So, without further adieu, here is my solution. I believe that you will find it much faster than the above solutions.
var elementBlockDisplays={"run-in":1,"block":1,"table-row-group":1,"table-column":1,"table-column-group":1,"table-header-group":1,"table-footer-group":1,"table-row":1,"table-cell":1,"table-caption":1,"inline-block:":1};
var getBlockParent = function(theElement){
var cur=theElement.parentElement;
while (cur&&!elementBlockDisplays[getComputedStyle(cur).display])
cur=cur.parentElement;
return cur;
};
0
user7892745
source
share