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