Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7612359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:53:26+00:00 2026-05-31T01:53:26+00:00

HTML : <form> <fieldset> <ul> <li class=answerFields> <input type=text value= /> <input type=text value=

  • 0

HTML :

<form>
<fieldset>
    <ul>    
        <li class="answerFields">
            <input type="text" value="" />
            <input type="text" value="" />
            <input type="text" value="" />
        </li>
    </ul>
</fieldset>
</form>

JQUERY :

$('.inputfield input').last().live('focus', function() {

    //this is just an example//
    document.write('a');
    ...
});

I have a fiddle.

I want to be able to check if the input that the user focuses is the last input in the <li>

constraints: I cannot change the HTML. The number of inputs will also be increasing or decreasing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:53:27+00:00Added an answer on May 31, 2026 at 1:53 am

    There are two problems in your code:

    1. $('.inputfield input').last().live(...) won’t work. .live() has to immediately follow the selector:

      Chaining methods is not supported. For example, $("a").find(".offsite, .external").live( ... ); is not valid and does not work as expected.

    2. document.write('a') will replace the current document. But I guess you only have it for testing. Still, you should be using console.log or append to the body.

    To answer the question:

    You can just check whether there are any following input elements or not:

    if($(this).nextAll('input').length === 0) {
        // this is the last input element
    }
    

    Alternatively, you could use the following selector if you only want to bind to the last input element:

    $('.inputfield input:last').live(...);
    

    Make sure you know about the many disadvantages of .live() [docs]. Consider to use .delegate() [docs] or .on() [docs] instead.

    You might also want to consider listening to the focus event instead of click. The focus can be changed with the tab key as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this HTML structure: <form> <input class=myTrigger type=radio value=1/> <input class=myTrigger type=radio value=2/>
I have a an HTML form which contains the YAHOO rich text editor on
I am implementing an HTML form with some checkbox input elements, and I want
<html> <head> <title>JSP Form</title> <style> </style> </head> <body> <form action=TestFileHandling.jsp method=post> <fieldset> <legend>User Information</legend>
I have a form and within it is this: <fieldset class=billing-address> <legend>Billing Address</legend> <ol>
The following HTML form successfully utilizes jQuery's form validation, displaying This field is required
In an HTML form post what are valid characters for creating a multipart boundary?
I am developing a HTML form designer that needs to generate static HTML and
I have a basic HTML form that gets inserted into a server side div
I am creating an HTML form with some radio button options. I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.