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 7802419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:15:35+00:00 2026-06-02T01:15:35+00:00

I understand how to use the remove/hide function inside of jQuery however this becomes

  • 0

I understand how to use the remove/hide function inside of jQuery however this becomes a little tricky for me.

I have a dropdown that has an if statement based on its selection. If the selection is 0 (which is the default) it should remove the datetime textbox’s parent div that has the classes of section and _100.

That way the whole part of that row in the form is removed. Obviously if the user selects “no” (value is 0) then it stays removed, and if they user selects “yes” then it shows that whole row so that the user can fill in the datetime the comments expire.

http://jsfiddle.net/ZMHkG

Any ideas on this?

  • 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-02T01:15:37+00:00Added an answer on June 2, 2026 at 1:15 am

    I’ve made some changes to the jsFiddle you provided which does what I think you were asking for. You can find the updated version here (code below).

    I used the .closest() jQuery function to get a reference to the <div> element that you want to hide in relation to the #datetime input, since it’s not the immediate parent.

    Then I changed the if statement to use the === operator, which compares values without modifying the types, and changed the value being compared against to the string '0' rather than the int 0.

    I removed the else if because it didn’t seem to serve any practical purpose, you only want to do something when the value is equal to '0'; if that’s not correct, you can always modify the code a bit to do that.


    HTML:

    <div class="section _100">
        <label for="comments">Allow Comments</label>
        <div>
            <select name="comments" id="comments">
                <option value="" selected="selected">Please Select An Option</option>
                <option value="0">No</option>
                <option value="1">Yes</option>
            </select>
        </div>
    </div>
    <div class="section _100">
        <label for="datetime">Date Comments Expire</label>
        <div>
            <input id="datetime" type="datetime" name="datetime" />
        </div>
    </div>
    

    jQuery:

    var dt= $("#datetime");
    var dtparent = dt.closest('div.section._100');
    
    $('#comments').change(function(){
    
        if($(this).val()==='0'){
            dt.val(''); //empty value
            dt.prop('disabled', true);
            dtparent.hide();
        }
        else{        
            dtparent.show();
            dt.removeAttr('disabled');                    
            dt.attr('validation','true');
        }    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that const_cast to remove constness of objects is bad, I have the
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
I'm trying to find some easy to understand and use tutorials for D3 that
I understand how to use the GeoChart to display a data that is in
I really dont understand why this is happening, bash seems to remove commands while
I am trying to understand this weird behaviour in VBA. I have two .NET
I understand why GUI controls have thread affinity. But why don't the controls use
Ok, I have these string prototypes to work with, however, I don't understand what
I understand that wanting to update or remove a constant is the exact opposite
I don't understand why livequery doesn't bind the event, but I have to use

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.