現在の要素のid属性が指定されているか調べる。
if ( typeof $( this ).attr( 'id' ) != 'undefined' ) {
/* 値が定義されている場合の処理 */
}
// 変数valを調べる場合は
if ( typeof val != 'undefined' ) {
/* 値が定義されている場合の処理 */
}
typeof演算子で値の型を取得できる。未定義の場合は’undefined’、文字列は’string’、数値は’number’、nullまたはオブジェクトは’object’となる。