Hiding elements in HTML by setting their display property to "

I'm struggling with this code:

   <div id="affichageRecherche"></div>
   <div class="row px-xl-9 d-flex justify-content-start" id="affichageCatalogue">(lot of code)</div>

At the bottom of the page, I have this script:

<script>
let searchSpareParts = document.getElementById('searchSpareParts');
let displaySearch = document.getElementById('displaySearch');
let displayCatalog = document.getElementById('displayCatalog');

        searchSpareParts.addEventListener('keyup', () => {
        if(searchSpareParts.value.length > 2){

            displayCatalog.style.display = "none";
            fetch('../../requetes/catalogue-piece-detachee.php?recherche='+searchSpareParts.value)
                .then(response => response.text())
                .then((response) => {
                    console.log(displayCatalog.style.display)
                    
                    displaySearch.innerHTML = response;
                })
                .catch(err => console.log(err));
                
        }else{
            displayCatalog.style.display = "block";
            displaySearch.innerHTML = "";
        }
    });
</script>

However, I'm encountering an issue where when the length of searchSpareParts.value is greater than 2, the line displayCatalog.style.display = "none" does not seem to work.

Even though the console displays "display: none", the block is still visible...

Here's a screenshot of the console

Can someone please assist me with this problem? Apologies for any language errors... :) Thank you!

Answer №1

The element contains the d-flex class. Typically, inline styles have the highest priority, but if a style rule includes !important, it will take precedence. Bootstrap utilizes the following code snippet:

.d-flex{
    display: flex !important;
}

Due to the presence of !important, this style rule will be applied, overriding any inline styles.

It is not advisable to use inline styles extensively. Instead, you can simply apply the d-none class, especially since you are working with Bootstrap.

https://i.sstatic.net/e1Vxv.png

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

Space empty on the right side of a card within a container - Bootstrap 4

I've been working on creating a responsive card for different screen sizes, but I've encountered a problem. On mobile screens, there seems to be some unwanted blank space on the right side of the card. Is there a way to center this card on smalle ...

The CSS legend for a FLOT plot chart is being unexpectedly replaced

I am currently exploring the FLOT plot tool and facing difficulty with the legend display. It seems that the CSS styling for the legend is somehow being overridden in my code, resulting in an undesirable appearance of the legend: Even when I try to specif ...

What is the best way to position a div vertically on the right side of another div?

I've been experimenting with different padding and margins to try and position the div below the dotted div. My goal is to have the div that's currently at the bottom appear vertically aligned to the right of the other div, similar to the layout ...

essential elements for mapping an array using typescript

Struggling to iterate through an array of objects, each with a unique id created by uuidv4(), resulting in a string type. TypeScript is giving errors (( Type 'String' is not assignable to type 'Key | null | undefined')) due to the &apos ...

Improving the innerHTML syntax

I am looking for the correct syntax to add content to an element using innerHTML. Here is an example that isn't working as expected: openNewWindow: function(content) { popupWin = window.open(content, 'open_window', 'menubar, ...

Encountering difficulties while attempting to convert JSON to XML resulting in an error being

I can't seem to figure out how to successfully convert the JSON result into XML format. I've tried the code below but it's not working as expected. Any help would be greatly appreciated. Here is the code snippet: <script src="../Jquery ...

Show only the present y-coordinate in the ToolTip of a chart.js

I am currently working on developing a chart using Chart.js, and my goal is to only show the y-axis value in the tooltip. The current display shows: date name_of_line: measurement example: Jan 1, 2020, 8:00:00 AM 5th Percentile: 100 oz. However, I would ...

The visibility of the Google +1 button is lost during the partial postback process in ASP.NET

When trying to implement the Google Plus One button using AddThis on one of our localized pages, we encountered a strange issue. Despite retrieving data from the backend (let's assume a database), the plus button was not loading during an AJAX based p ...

Argument for setInterval function

As a newcomer to programming, I am attempting to develop a basic javascript game. I have encountered an issue with the window.setInterval function and it seems to be causing everything to malfunction. I have been following a tutorial at this link and att ...

extract information from the request header

One of the functionalities in my application involves making Ajax requests to the server. $.ajax({ type: "get", beforeSend: function (jqXHR) { jqXHR.setRequestHeader(ZO_KEY1, _key1); jqXHR.setReq ...

Execute an xmlhttprequest and then redirect to a different URL

I'm a beginner when it comes to AJAX and JavaScript. My goal is to first show a confirmation box, then send an XMLHttpRequest if confirmed. After that, I want to redirect the user to a new page. Below is my current code: <script type="text/javascr ...

Sending data to a PHP page to maintain state in an Angular application

Here is my current setup: In a dynamic Angular environment, I have various states connected to PHP pages. These PHP pages rely on specific data variables, typically provided as GET parameters outside of Angular. Now, I am looking for a way to switch to a ...

Converting JavaScript code from storeEval to executeScript_Sandbox in Selenium IDE using Kantu Ui.Vision

Looking for assistance with converting two snippets of Javascript code to extract date and time in a specific format, transitioning from storeEval to executeScript_Sandbox for use in Selenium Ide Kantu Ui.Vision. Due to recent updates, storeEval is now de ...

Difficulty accessing context.params query in Next.js Dynamic Path

I've almost completed setting up a dynamic page in Next.js using getStaticPaths(), but I'm running into an issue with the getStaticProps() function not referencing the URL query correctly to load the relevant information. Here is my code: //Get ...

The filtering feature in AngularJS ng-options is not functioning correctly

Greetings, I am a newcomer to angular. In my current demo application, I have created a list of users with a select filter using ng-option. There seems to be a bug that I have been unable to identify. The issue: When I select the Female option, i ...

What are the steps for testing React components when they are wrapped by ThemeProvider/withStyle?

Is there a way to properly test a component that is wrapped with withStyle, as it seems the theme object does not pass through the component. Any suggestions on best practices for achieving this? I am considering using createShallow() and dive() methods t ...

Invoking function through click event binding

Check out this fiddle I have: http://jsfiddle.net/jj258ykp/2/ On BTN2 and BTN3, I get an alert when I click, but not on BTN1. I want to see the alert on BTN1 as well. Take a look at the coffeescript code snippet below: class A method: -> ...

What causes ng-options to return an empty array in AngularJS when using $element.find('option')?

For my project in Angular 1.4, I am utilizing the ngOptions directive to dynamically fill a <select> element with <option> elements based on an object structure like this: {black: '#000000', red: '#FF0000', ...} The implem ...

Guide to emphasizing text with hover effects and excluding whitespace (javascript)

Currently, I am utilizing jQuery for hover highlighting purposes. However, I am facing an issue where the entire div gets highlighted instead of just the text. I attempted to use an "a tag" but don't want a reference link. I know this should be a simp ...

Can I safely keep a JWT in localStorage while using ReactJS?

As I work on developing a single page application with ReactJS, one question comes to mind. I came across information indicating that using localStorage may pose security risks due to XSS vulnerabilities. However, given that React escapes all user input, ...