jquery 检测元素是否存在

  1. if ($('#myDiv).length) {
  2. // your code
  3. }
  4. Simple, but not obvious.