I was really sure I had properly searched the online documentation
before posting this problem but a 're-read' revealed the solution ie

$(document).ready(function(){
    $('input:text').click(function () {
      var index = $('input:text').index(this);
      $('div').text("That was div index #" + index);
    });

  });

Apologies for not checking things out properly.

Paul

On 22 Feb, 23:12, paulj <[EMAIL PROTECTED]> wrote:
> As each text box gains the focus, I would like the index number of
> that text box to be displayed in a div.
>
> I tried to use the following but  -1 was displayed each time.
>
> $(document).ready(function() {
>         $('input:text').focus(function () {
>             $('div').text(  $(this).index());
>     });
>     });
>
> Here is the full HTML markup and jQuery code.  TIA
>
> <html>
> <head>
> <title></title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=ISO-8859-1">
> <script type = "text/javascript" src="jquery.js"></script>
> <script type = "text/javascript">
>
> $(document).ready(function() {
>         $('input:text').focus(function () {
>             $('div').text($(this).index());
>     });
>     });
>
> </script>
>
> </head>
> <body>
>
> <form>
>   <input type='text'>
>   <input type='text'>
>   <input type='text'>
> </form>
>
> <div>index number to be displayed here</div>
>
> </body>
> </html>

Reply via email to