nextwebgen.com

The Next Generation Web Now

Browser CSS float error detection with jQuery

Filed under: Web 2.0 News — Dion Almaer at 6:30 am on Monday, March 31, 2008

Mario Heiderich of Ormigo has created a jQuery based code snippet/bookmarklet that is capable of detecting floating errors and adding a dotted orange border to elements which should be cleared - but aren’t.


It saved me a huge bunch of time debugging complex layouts for all browsers - especially IE6. If jQuery isn’t already loaded on the page it can easily be fetched with the several jQuerify approaches.

Snippet

JAVASCRIPT:

  1.  
  2. (function(){
  3.     function checkNext(element, floating) {
  4.             if(element.css(‘clear’) != ‘none’) {
  5.                 var clearing = true;
  6.             } else {
  7.                 if(element.next().length !== 0) {
  8.                     var clearing = false;           
  9.                     checkNext(element.next(), floating);
  10.                 } else {
  11.                     console.log(element);
  12.                     element.css({border:‘2px dotted orange;’})
  13.                 }
  14.             }
  15.     }
  16.     $(‘body *’).each(function(){
  17.         var element = $(this);
  18.         if(element.css(‘float’) !== ‘none’ && element.next().length !== 0) {
  19.             checkNext(element.next(), element.css(‘float’));
  20.         }
  21.         eval(‘’);
  22.     });
  23. })();
  24.  

Bookmarklet

JAVASCRIPT:

  1.  
  2. javascript:eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!‘’.replace(/^/,String)){while(c–)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return\\w+’};c=1};while(c–)if(k[c])p=p.replace(new RegExp(\\b’+e(c)+\\b’,‘g’),k[c]);return p}(‘(3(){3 5(a,b){4(a.2(\’p\’)!=\’9\’){6 c=h}d{4(a.1().7!==0){6 c=o;5(a.1(),b)}d{n.m(a);a.2({l:\’j i k;\’})}}}$(\’g *\’).f(3(){6 a=$(e);4(a.2(\’8\’)!==\’9\’&&a.1().7!==0){5(a.1(),a.2(\’8\’))}q(\’\’)})})();’,27,27,‘|next|css|function|if|checkNext|var|length|float|none||||else|this|each|body|true|dotted|2px|orange|border|log|console|false|clear|eval’.split(‘|’),0,{}))
  3.  

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blogmarks
  • del.icio.us
  • De.lirio.us
  • digg
  • NewsVine
  • YahooMyWeb

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>