if ($('#myDiv').length) {  
    // your code  
}