Question: I am trying to focus on credit card validation fail. but strange `focus()` not working. 

```
$('#cc_number').validateCreditCard(function (result) {
    if (result.length_valid && result.luhn_valid) {

    } else {
       $("#cc_number").focus();
       return false;
    }
});

<input  type="text" id='cc_number' name="cc_number" />

```

Answer: 
As [mentioned in the comments](https://stackoverflow.com/questions/18383747/jquery-focus-not-working/18383855#comment26996865_18383747), your original jsfiddle contains the solution.

A workaround is to put a timeout on the focus call.

```
setTimeout(function(){
    $("#cc_number").focus();
}, 0);

```

I'm not 100% sure, but it could be that as the alert is called on blur, you're never actually allowing the textbox to lose focus, and therefore when focus is called, it already has it.

By using a timeout, you are putting the logic into a seperate thread, which runs seperate to the main javascript code (much like a callback function).

---

But as your question comments also mention, forcing focus until validation passes is annoying.

But this is more of a UX criticism.
Your DOM may be getting refresh so focus is not working here. Instead you can follow this approach:

```
$('#cc_number').validateCreditCard(function (result) {
    if (result.length_valid && result.luhn_valid) {

   } else {
      $("#cc_number").attr("autofocus","autofocus")
      return false;
   }
});

```