if ( $("#mydiv").length ){
// do something here
}
Briefer again…
if ( $("#mydiv")[0] ){
// do something here
}
via http://aaronrussell.co.uk/legacy/check-if-an-element-exists-using-jquery/
if ( $("#mydiv").length ){
// do something here
}
Briefer again…
if ( $("#mydiv")[0] ){
// do something here
}
via http://aaronrussell.co.uk/legacy/check-if-an-element-exists-using-jquery/
Want the best way to trim a sting in javascript?
A while ago, I came across a post on such a subject. It was written a few years ago but it’s still as relevant and useful as ever.
Something that has bugged me recently is that when I go to proxy on a particular port, the port is already in use and I get the following error.
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 8090
Could not request local forwarding.
Continue reading
I have written a simple tool to tidy assignments. It basically takes a group of assignments and uses spaces to make the code more readable.
This tool will help code meet the indentation rules in the WordPress coding standards.
Continue reading
This is a super simple command but there is something about the following sequence of characters that I simply cannot retain in my brain.
Continue reading
Simple function to check if XML is valid. It just loads the XML into DOMDocument and checks for errors.
/**
* Takes XML string and returns a boolean result where valid XML returns true
*/
function is_valid_xml ( $xml ) {
libxml_use_internal_errors( true );
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML( $xml );
$errors = libxml_get_errors();
return empty( $errors );
}
Here is a function to find duplicate items in an array.
/**
* Takes an array and returns an array of duplicate items
*/
function get_duplicates( $array ) {
return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
}