Search code examples
jqueryjquery-1.3

jQuery focus function not working in Firefox


The following piece of code focuses the text input after you click on the link. It works fine for Chrome 2.x, IE8 and Opera 9.64 but not on Firefox 3.0.9. The text input flashes quickly in Firefox then disappears, I'm currently working on Windows XP SP2.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
<script>
$(document).ready(function()
{
    $("a").click(function() {
        var field_id = $(this).attr("href");
        $(field_id).focus();
    });
});
</script>

<a href="#text_field">Focus</a>
<input type="text" name="text_field" id="text_field" />

Does anyone know how to handle the above in Firefox?


Solution

  • I don't know if is this you want. To put focus on the input clicking on the label you can do this:

    <label for="text_field">Label</label>
    <input type="text" name="text_field" id="text_field" />
    

    OR

    <label>Label
    <input type="text" name="text_field" id="text_field" />
    </label>