Checking type of element seems dirty.. can you just check if ( $element ) ?