1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
var block_elements = ["address", "blockquote", "del", "div", "dl", "fieldset", "form", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "ins", "noscript", "ol", "p", "pre", "script", "table", "ul"];
// Obviously this assumes that the input is well-formed and there *is* a block node somewhere up the hierarchy
function get_block( node ) {
var found = false;
while( found == false && node != null ) {
var i = 0;
while( node.nodeName != block_elements[i] && i < block_elements.length ) {
i++;
}
if( i == block_elements.length ) {
node = node.parentNode;
}
else {
found = true;
}
}
return node;
};
|