Community Member Profile
- Profile: /members/4522--Cowboy-Ben-Alman.htm
- URL: http://benalman.com/
- Comments: 19
- Points: 205
Recent Blog Comments By "Cowboy" Ben Alman
-
Empty SRC And URL() Values Can Cause Duplicate Page Requests
Posted on Aug 4, 2011 at 11:59 AM
Ben, check out this article by Nicholas Zakas: http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/... read more »
-
Experimenting With Sub() And Deferred Objects In jQuery 1.5
Posted on Feb 17, 2011 at 10:48 AM
Ben, check out this gist for another way to use $.sub: https://gist.github.com/804811... read more »
-
Using SetTimeout() To Delay The Closing Of A Related UI Element Based On User Interactions
Posted on Oct 4, 2010 at 11:15 AM
Ben, take a look at my jQuery doTimeout plugin, which is very useful for delayed code execution, especially when dealing with polling loops or hover intent: http://benalman.com/projects/jquery-dotimeout-plugin/<... read more »
-
Using Named Functions Within Self-Executing Function Blocks In Javascript
Posted on Aug 16, 2010 at 10:44 AM
One caveat to this method is that it doesn't work in BlackBerry OS 5.x or earlier, as the code inside the named function expression can't access the the function by name (for whatever reason). So, if you're writing cross-OS mobile JavaScript, you should avoid this pattern. See read more »
-
Experimenting With jQuery's Queue() And Dequeue() Methods
Posted on Jun 17, 2010 at 6:46 PM
@tylik, it might be more helpful if you fork my gist on GitHub and ask your question there, so that we get the benefit of syntax highlighting, indenting, comments and revisions. http://gist.github.com/319568... read more »
-
Javascript's IN Operator Does Not Work With Strings
Posted on May 11, 2010 at 8:50 AM
Why not just test if ( typeof arg === 'string' ) { ... } ?... read more »
-
Experimenting With jQuery's Queue() And Dequeue() Methods
Posted on Mar 2, 2010 at 10:14 AM
BTW, here's my code as a gist for easier viewing: http://gist.github.com/319568... read more »
-
Experimenting With jQuery's Queue() And Dequeue() Methods
Posted on Mar 2, 2010 at 10:09 AM
@Ben, I like SyntaxHighlighter personally.. you can see it in my site's comments, plugin code examples, etc. Easy to use and flexible. http://alexgorbatchev.com/wiki/SyntaxHighlighter Regarding the queueing... read more »
-
Experimenting With jQuery's Queue() And Dequeue() Methods
Posted on Mar 2, 2010 at 9:47 AM
Man, I wish there was comment code syntax highlighting.... read more »
-
Experimenting With jQuery's Queue() And Dequeue() Methods
Posted on Mar 2, 2010 at 9:47 AM
It's especially useful when have a series of asynchronous method calls that you want to execute serially, and don't want to maintain a chain of callbacks. Say you want to execute first_async_action() followed by second_async_action(), followed by third_async_action(). You could do this:... read more »
-
Selecting The Closest Parent On Multiple Nodes With The jQuery Plugin ClosestParents()
Posted on Feb 15, 2010 at 10:54 AM
@Ben, I haven't done any testing, but I'm sure that: jQuery( node ).parent().closest( selector ) will be faster than: jQuery( node ).parents( selector ).first() because while .parents() collects *all* parent elements, traversing all the way up the hierarchy before filterin... read more »
-
Selecting The Closest Parent On Multiple Nodes With The jQuery Plugin ClosestParents()
Posted on Feb 15, 2010 at 9:50 AM
Gotcha, makes sense!... read more »
-
Selecting The Closest Parent On Multiple Nodes With The jQuery Plugin ClosestParents()
Posted on Feb 15, 2010 at 9:38 AM
Hey Ben, instead of: result = result.add( jQuery( node ).parents( selector ).first() ); Why not do: result = result.add( jQuery( node ).closest( selector ) );... read more »
-
Creating A Sometimes-Fixed-Position Element With jQuery
Posted on Jan 12, 2010 at 10:40 AM
I like the approach where the element starts with a position: static (rendered in the normal flow of the document) and when the page is scrolled away from the top (or past the element's top offset), the element gets position: fixed. Of course, that doesn't work in IE6.. so you have to test... read more »
-
Using Logical Operators To Perform Ternary Operations In Javascript
Posted on Nov 18, 2009 at 11:49 AM
Another example (that Paul and I have already discussed) of where function invocation can be an issue with logical || and && is in the slide he just mentioned: data = window.JSON && JSON.parse(data) || eval('('+data+')'); If window.JSON exists, JSON.parse(data) is called.. but what if... read more »
-
Using Logical Operators To Perform Ternary Operations In Javascript
Posted on Nov 18, 2009 at 11:41 AM
@Ben, Sorry for the confusion.. the problem would be if you were actually invoking the function like: var value = "foo"; window.console && console.log( value ) || alert( value ); In that case it would both log and alert, since even though console.log exists, when it's invok... read more »
-
Using Logical Operators To Perform Ternary Operations In Javascript
Posted on Nov 18, 2009 at 11:22 AM
@Ben, this is a perfect example of where *not* to use logical && and ||: var logger = ((window.console && window.console.log) || window.alert); What if console.log returns undefined? Then it logs AND alerts. I'm guessing that's not what you want. This is probably what you want:<... read more »
-
Using Logical Operators To Perform Ternary Operations In Javascript
Posted on Nov 18, 2009 at 11:08 AM
Think about it this way: When || is encountered, if the preceding expression was truthy, evaluation stops and that truthy value is returned. When && is encountered, if the preceding expression was falsy, evaluation stops and that falsy value is returned. Otherwise, things contin... read more »
-
jQuery Plugin: From - Filtering A Collection Based On Ancestors
Posted on Oct 13, 2009 at 1:53 PM
Ben, looks useful. One suggestion though, I'd love to see your code include a private from method that both $.fn.from and $.expr[':'].from utilize. That way you could use from as both a method and a psuedo-selector!... read more »



