Archive for the ‘Uncategorized’ Category
Detect an Empty Set in jQuery Saturday, April 24th, 2010

I spent over a half hour looking for the best solution to this.  Personally, I blame the jQuery documentation.  When reading over the jQuery core description it states, starting in version 1.4, that jQuery returns an empty set but offers no method to detect it.  Ultimately, I found that .length is the way to go but I wanted to expound on all three methods I discovered.

count with javascript

  1. function jQueryCount(obj) {
  2.   var len = 0;
  3.   for (var k in obj)
  4.     len++;
  5.   return len;
  6. }

This was the first type of solution I found.  Actually, I haven’t even tried it.  I knew right off the bat there has to be a built in jQuery function so I kept digging…

.size()

  1. if ($(‘ul li:visible’).size()==0) {
  2.   /* do stuff here if no visible li elements exist */
  3. }

Yes! After scouring the API documentation for 20 minutes I finally stumbled upon what I was looking for — .size() It returns a count of elements inside a jQuery object. If there are no elements in the object it returns zero.

But what’s this?!?! The comments on the entry say it’s a stupid function that should be deprecated. The page suggests something better…

.length

  1. if ($(‘ul li:visible’).length==0) {
  2.   /* do stuff here if no visible li elements exist */
  3. }

.length works in a different way to get a similar answer.  It seems to be “faster, and more consistent to JavaScript in general”.  I hope this is helpful to someone in a similar situation!  :D

Spring Forward Sunday, March 14th, 2010

I took this photo but I didn't remove the snow! :o

Birds and bees outside!??!  The clock in my minivan displays the correct time now?!?!  I lost an hour of sleep!??!?  HOLY BAJEEEZUS!

Our Hero Sunday, March 7th, 2010

I got out of bed at 2pm; in the midst of great grogginess I checked Battle of the Bits for any activity and was heroically surprised!  Strobe, a venerable BotBr, effortlessly coagulated a victoriously stunning viral video with a photo of myself from, liek, 6 years ago.  I both laughed and scoffed like a junior high hermaphrodite at such the glorious wakeup surprise!

Watch it / Make your own here.

Hello World! Sunday, February 21st, 2010

OH!  What do ya know?  It’s time for da B-Knox to join the bloggosphere!  It’s just another WordPress installation against the world.  Still ironing out the kinks of the layout, dress to impress!  :o

Wordpress is new and so is my account at SoundCloud and so a merry “Hello World!” to you all.  :D

baron knoxburry – energy box dub by  Baron Knoxburry

This track was written last August but I share it now.