Created
May 10, 2011 14:17
-
-
Save mfields/964552 to your computer and use it in GitHub Desktop.
Hide submit button if it exists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Hide submit button if it exists. */ | |
var button = document.getElementById( 'my_submit_button' ); | |
if ( null !== button && 'style' in button && 'display' in button.style ) { | |
button.style.display = 'none'; | |
} |
Thanks for taking a look! Does checking for (!==) have a larger footprint over (!=)? I know this is something that WordPress core makes a point to do and I'm comfortable knowing when and where to check for such values in php. Javascript's a whole different animal though.
The ===
and ==
operators behave exactly the same after doing type conversions. In the end, ===
is faster if the two sides are different types (because it skips type conversion and just returns false) but ==
is faster if the two types are the same.
In your case, particularly when using Yoda conditions, there's no benefit of using one or the other since you're comparing with null. It becomes a matter of preference.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks very solid and does a great job of checking things progressively. Though you might be able to get away with a != rather than an !== for your first check. If document.
getElementById( 'my_submit_button' )
fails to find an element, it will return null. So you can check either equality (==) or identicality (===) and get the same result. In the end, it's the addition of a single character, so it doesn't make too much of a difference.