Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
up: function(element) { if(!arguments[1]) return element.parentNode; if(typeof arguments[1] == 'number') { arguments[1].times(function(){ element = element.parentNode }); return element; } var filter = arguments[1]; while((element = element.parentNode) && element.parentNode) { var match = true; for(key in filter) switch(key) { case 'class': case 'className': if(!$(element).hasClassName(filter[key])) match = false; break; case 'tag': case 'tagName': if(element.tagName.toUpperCase()!=filter[key].toUpperCase()) match = false; break; default: if(element[key]!=filter[key]) match = false; } if(match) return element; } }, // examples testElementUp: function() { with(this) { assertEqual('Container', $('collect').up().id); assertEqual('Container', $('collect').up(1).id); assertEqual('Container', $('5').up(2).id); assertEqual('Container', $('collect').up({tagName:'DIV'}).id); assertEqual('4', $('5').up({className:'thirdClass'}).id); assertEqual('Container',$('5').up({className:'moo',tagName:'DIV'}).id); assertEqual('Container',$('5').up({tag:'div'}).id); assertEqual('Container',$('5').up({'class':'moo','tag':'div'}).id); assertNull($('5').up({className:'moo',tagName:'IMG'})); }}, /* for this HTML <div id="Container" class="moo hoo"> <span id="1" class="firstClass">First class</span> <span id="2" class="secondClass">Second class</span> <span id="3" class="firstClass secondClass">First and Second class</span> <span id="4" class="thirdClass">Third class <span id="5" class="firstClass">Nested First class</span></span> <div id="collect">1<span class="ignore"><span class="someclass">2</span>3</span><ul><li class="ignore">4</li></ul></div> </div> */
This paste will be private.
From the Design Piracy series on my blog: