Set focus depending on error

Set focus depending on error

Hi,

Maybe someone can help me with the following. Currently I'm trying to use jquery in an ApEx application. I'm almost there but not quit yet (this is the first time I'm using jquery).

I've got the following code:

  $(document).ready(function(){
    var err_item = $("span[class='errTxt']").parent().parent().find("input[type!='hidden']");
    alert(err_item);
    if (err_item){
      alert ("1");
      err_item.focus();
    } else {
      alert("2");
      $("input[type!='hidden']")[0].focus();
    }   
  });


When the page starts and has no error, the focus must to be set on the first available item. If there is an error, the focus must be set on the item which generates the error.

The pages works when there is an error. The focus is set on the error input field. But, when there is no error, the focus isen't set...

The message alert ("1"); is always shown...

Has anyone got any idea what I'm doing wrong?