Struggling to conceal HTML element

I have been attempting to hide or completely conceal certain fields within the item class using jQuery, JavaScript, and HTML, however, the outcome has not been satisfactory.

<div class="item">
        <label for="id_mobile_number">Mobile number:</label>: <input type="text" name="mobile_number" 
       maxlength="12" required id="id_mobile_number">
</div>
                
    <div class="item">
         <label for="id_ported_number">Ported number:</label>: <input type="text" name="ported_number" 
          value="true" maxlength="100" id="id_ported_number">
    </div>
            

<div class="item">
          <label for="id_idplan">Idplan:</label>: <select name="idplan" required id="id_idplan">
           <option value="" selected>---------</option>
           <option value="1">500 at 150 for 1month</option>
</select>
</div>
<div class="item">
          <label for="id_user">User:</label>: 
          <select name="user" id="id_user">
           <option value="">---------</option>
           <option value="2"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9afbf1eae9e8dafdf7fbf3f6b4f9f5f7">[email protected]</a></option>
           <option value="3"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e6e5eec7e0eae6eeeba9e4e8ea">[email protected]</a></option>
          </select>
</div>    






I am striving to make these specific fields invisible or entirely hidden with HTML, ensuring that users cannot detect any missing items on the form.

Check my code below:

I attempted to use JavaScript to hide only the input field, but the remaining properties still display:
    <script type="text/javascript">
      var net = document.getElementById('id_idnetwork');
       net.style.display = 'hidden';
    
    
    
    </script>

Similarly, when utilizing HTML, I found that only the input is hidden while other properties remain visible. Here is how I tried to achieve this using HTML IDs:

#id_user {
        position: absolute;
        display: none

      }
      #id_idplan {

        position: absolute;
        display: none
      }

Answer №1

You have the option to conceal siblings:

[for="id_user"],
[for="id_user"] ~ * /* hide siblings */
{
  position: absolute;
  display: none

}
[for="id_idplan"],
[for="id_idplan"] ~ * /* hide siblings */
{

  position: absolute;
  display: none
}
<div class="item">
        <label for="id_mobile_number">Mobile number:</label>: <input type="text" name="mobile_number" 
       maxlength="12" required id="id_mobile_number">
</div>
                
<div class="item">
     <label for="id_ported_number">Ported number:</label> <input type="text" name="ported_number" 
      value="true" maxlength="100" id="id_ported_number">
</div>
            

<div class="item">
          <label for="id_idplan">Idplan:</label> <select name="idplan" required id="id_idplan">
           <option value="" selected>---------</option>
           <option value="1">500 at 150 for 1month</option>
</select>
</div>
<div class="item">
          <label for="id_user">User:</label> 
          <select name="user" id="id_user">
           <option value="">---------</option>
           <option value="2"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbeb4afacad9fb8b2beb6b3f1bcb0b2">[email protected]</a></option>
           <option value="3"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d7c7f745d7a707c7471337e7270">[email protected]</a></option>
          </select>
</div>

Alternatively, a more efficient approach would be to assign additional classes to the .item elements for better control:

.item4 {
  position: absolute;
  display: none;

}
.item3 {

  position: absolute;
  display: none;
}
<div class="item item1">
        <label for="id_mobile_number">Mobile number:</label>: <input type="text" name="mobile_number" 
       maxlength="12" required id="id_mobile_number">
</div>
                
<div class="item item2">
     <label for="id_ported_number">Ported number:</label>: <input type="text" name="ported_number" 
      value="true" maxlength="100" id="id_ported_number">
</div>
            

<div class="item item3">
          <label for="id_idplan">Idplan:</label>: <select name="idplan" required id="id_idplan">
           <option value="" selected>---------</option>
           <option value="1">500 at 150 for 1month</option>
</select>
</div>
<div class="item item4">
          <label for="id_user">User:</label>: 
          <select name="user" id="id_user">
           <option value="">---------</option>
           <option value="2"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="33525843404173545e525a5f1d505c5e">[email protected]</a></option>
           <option value="3"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b6b5be97b0bab6bebbf9b4b8ba">[email protected]</a></option>
          </select>
</div>

Answer №2

Maybe it could be done like this?

#id_user {
        position: absolute;
        display: none
      }
      
      
 #id_idplan {
        position: absolute;
        display: none
}

label#hide_user {display:none;}

select#hide_user {display:none;}
<div class="item">
        <label for="id_mobile_number">Mobile number::</label> <input type="text" name="mobile_number" 
       maxlength="12" required id="id_mobile_number">
</div>
                
    <div class="item">
         <label for="id_ported_number">Ported number::</label> <input type="text" name="ported_number" 
          value="true" maxlength="100" id="id_ported_number">
    </div>
            

<div class="item">
          <label id="hide_user" for="id_idplan">Idplan::</label> <select id="hide_user" name="idplan" required id="id_idplan">
           <option value="" selected>---------</option>
           <option value="1">500 at 150 for 1month</option>
</select>
</div>
<div class="item">
          <label id="hide_user" for="id_user">User:: </label>
          <select name="user" id="id_user">
           <option value="">---------</option>
           <option value="2"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e88983989b9aa88f85898184c68b87">[email protected]</a></option>
           <option value="3"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6c7c4cfe6c1cbc7cfca88c5c9cb">[email protected]</a></option>
          </select>
</div>

Answer №3

Ever since the debut of HTML5, a simple method has been introduced:

<div hidden>This div is now concealed</div>

Please keep in mind that this feature may not be fully compatible with older browsers, particularly pre-IE 11 versions.

For more information on the Hidden Attribute, refer to the documentation from MDN and W3C.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript and Ajax are functioning properly in Mozilla Firefox, however there seem to be some compatibility issues with Google Chrome

I have a form that serves the dual purpose of registration and login, and I am using JavaScript Ajax to submit it. While it works smoothly in Mozilla Firefox, it fails in Chrome and IE. The goal is to execute an AJAX and PHP script that checks the databa ...

Guide on utilizing the <source> tag within v-img component in Vuetify.js?

When it comes to using webp images instead of jpg or png, some browsers may not support the webp format. In such cases, we can use the html tag < source > as demonstrated below, ensuring that at least a jpg image is displayed: <picture> < ...

Using PHP, JavaScript is unable to hide <div> elements

I'm encountering an issue where the div I want to show when an error occurs is not hiding and showing properly using JavaScript. Here is a snippet of my code: <script> function hideerror() { var catdiv = document.getElementById(error); ...

Modifying a leave transition in Vue.js dynamically following the completion of an enter transition

I am dealing with a dynamic transition for a slider element that moves left or right. Vue only allows me to have one transition, so I am using a dynamic transition property like this: <transition v-bind:name="'slider-' + slideDirection"> ...

Retrieve specific rows and columns using the jQuery Selectable plugin

I'm currently utilizing the jQuery ui Selectable plugin, which is performing as expected. However, my next objective is to retrieve the total number of selected rows and columns. I plan on using these values along with jQuery .attr to group the select ...

I am experiencing an issue with my jQuery ajax where my return function is not working as expected

I'm currently working on the following code snippet: $("#upvote").click(function(){ var up = parseInt(document.getElementById('voteScore').innerHTML); up++; document.getElementById('voteScore').innerHTML = up; $.aj ...

Outlook's limited width is causing images to exceed the boundaries of the HTML email

I have a collection of images that display perfectly in Gmail, but when viewed in Outlook, all five images appear within a single <tr> and cause the table width to expand. My desired layout is to have the first four images centered on the first line ...

Styling Tip: Aligning text to the baseline of a height-adjusted input field using CSS

As per the information from the Mozilla documentation, it states that I can align the text in an input field to the baseline if the element's display property is set to inline-block. I have made adjustments to the height of several input elements, bu ...

The jQuery UI Sortable functions are being triggered at lightning speed

I am currently working on a project where users can create a seating chart, add rows and tables, and move the tables between different rows. The functionality for adding rows and moving tables already exists in the code. However, I am facing an issue where ...

Preventing long int types from being stored as strings in IndexedDB

The behavior of IndexedDB is causing some unexpected results. When attempting to store a long integer number, it is being stored as a string. This can cause issues with indexing and sorting the data. For instance: const data: { id: string, dateCreated ...

To access a restricted selection of images stored in Firebase

Is there a way to load additional images from Firebase by clicking a button? I created a function that looks like this: onLoadMore() { if (this.all.length > 1 ) { const lastLoadedPost = _.last(this.all); const lastLoadedPostKey = lastLoadedP ...

developing a click animation for buttons using JQuery

I'm curious about how to create a button press effect using JQuery. One idea I had was to use a mouse click event to change the image to a pressed state and then return it back to its original state when the mouse is released. Do you have any thought ...

Javascript - Button animation malfunctioning after first click

One issue I'm facing is with an animation that is triggered using the onmousedown event. Another function is supposed to stop the animation when onmouseup is detected. The problem arises after the first time it works correctly. Subsequent attempts to ...

The image generation process by NReco.ImageGenerator encountered an error while creating an image from

Currently, I am attempting to convert HTML into JPG files by utilizing the NReco.ImageGenerator NuGet package. Although the 'GenerateImageFromFile' function typically produces the desired output, there are instances where the DLL throws the follo ...

What is the best method for passing parameters from HTML to AJAX within code?

My project involves working with Flask, HTML, and Ajax. Here is the HTML code snippet: <script type=text/javascript> $(function() { $('a#calculate').bind('click', function() { $.getJSON('/_add_numbers&ap ...

What is the best method for designing a slideshow with a background image on the body

I have been on a quest to find a simple background slideshow that fades images for the body of my website. Despite trying multiple Javascript options and CSS solutions, I have had no success. Someone suggested creating a DIV for the background, but I am ...

Steps to stop mat-spinner upon receiving Job Success/Failure Notification from the backend

I have a task that runs asynchronously and takes a long time to complete. When the task starts, I display a mat-spinner with a timeout set at 60000 milliseconds. However, we now have a notification service that provides updates on the job status. I would l ...

Determine the total accumulation of time entities in VueJS

My task involves working with an array of time objects that users will add. The array comprises values like this, with a generic example of "01:01:01" for each date value. let timeObjects = ["01:01:01", "01:01:01", "01:01:01"]; The goal is to iterate thro ...

Ways to pass properties while using render in reachrouterdomv6?

Currently, I am enrolled in a Udemy course, but the information provided is based on v5. I am struggling to understand the equivalent of "render" and how to pass props with it. Additionally, there seems to be an issue with the code - if the element is un ...

Different ways to rearrange the placement of Export buttons in a personalized div or outside the table using Datatable

I would like to display the export buttons outside of the table. While searching on stackoverflow, I came across an example that uses the Select options method. You can find the example here. If anyone knows how to achieve this, please modify it and shar ...