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

  • SEARCH
  • Home
  • 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 8514591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:54:45+00:00 2026-06-11T04:54:45+00:00

I am using jQuery selector to hide and unhide some dynamically generated HTML cells.

  • 0

I am using jQuery selector to hide and unhide some dynamically generated HTML cells. However, it seems like I did not choose the right selector. So, I appreciate if you could give me some suggestions.

The webpage:

  1. first ask users to select the number of applications
  2. based on users selection, generate two input fields “Application timing”, and “Application Date” for each application.
  3. There are two options in the “Application timing”. If the user chooses “Default”, the “Application Date” will disappear.

Problem:
When there are more than three applications, only the last “Application Date” will disappear, not matter where the selection is made. I think it is because I did not use the right selector.

DEMO

HTML CODE

<table class="table">
    <tr>
        <th>
            <label for="id_NOA">Number of applications:</label>
        </th>
        <td>
            <select id="id_NOA" class="valid" name="NOA">
                <option selected="selected" value="">Choose</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
            </select>
        </td>
    </tr>
</table>

JavaScript

$(document).ready(function() {
    $('#id_NOA').change(function() {

        var total = $(this).val();
        $('.app_timing').remove();
        $('.app_dates').remove();

        for (var i = 1; i <= total; i++) {

            $('<tr class="app_timing"><th><label for="id_Apt' + i + '">Application timing ' + i + ':</label></th><td><select name="Apt' + i + '" id="id_Apt' + i + '"><option value="" selected="selected">Select an application timing</option><option value="1">Default</option><option value="2">Enter your own</option></select></td></tr>').appendTo('.table')

            $('<tr class="app_dates"><th><label for="id_Date_apt">Application Date ' + i + ':</label></th><td><input readonly="readonly" type="text" name="Date_apt' + i + '" value="MM/DD" id="id_Date_apt' + i + '"/><td></tr>').appendTo('.table')

            $('.app_timing:last').find('select').bind('change', function() {
                if ($(this).val() == '1') {
                    $('.app_dates:last').hide()
                //$('#id_Date_apt' + i).hide() //I tried to use ID selector, but it does not work 
                }

            })
        }
    })


})​
  • 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-06-11T04:54:47+00:00Added an answer on June 11, 2026 at 4:54 am
    $('.app_dates:last').hide()
    

    The above line is within the change handler and is not executed until the handler fires. At the time it fires, this will get the last element, which causes the behavior you observed. You can use the following:

    $(this).closest("tr").next().hide()
    

    Note that this is based on your current html. A change would require this to change. It simply hides the next row in the table.

    EDIT:

    While the above answers the question, an overall better approach would be to use event delegation. This will allow you to attach a single handler rather than creating new handlers every time the dropdown is changed. (Note that I added a class to each select to simplify the selector)

    $(".table").on("change",".timeSel",function(){
        var $this = $(this);
    
        if ($this.val() == '1') {
            $(this).closest("tr").next().hide();
        }
    });
    

    http://jsfiddle.net/JDFcn/11/

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

Sidebar

Related Questions

I have a problem with selecting not first selector using attributeContains jQuery('div[id*=abc]:not(:first)').hide();
I want to use jquery append() using an id as my selector, however the
Using jQuery and backbone.js, I would like to separate the JavaScript from the HTML
When using Jquery to exclude elements from selection I like to use CSS :not
Seems like $(img).next().hide(); is not working when both the image and div tag are
Using Jquery, how do I find and hide elements like this? <p>MyHeader</p> The only
jQuery's :visible selector seems not to work on TR elements in Internet Explorer 8
what does it mean where there are two id's in the jquery selector using
I am using JQuery's nth-child selector to alter the margin on every 3rd div
I am new to jQuery and cannot get a selector to work using the

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.