Unable to conceal a div that was generated by Javascript

I have a basic HTML webpage.

<!DOCTYPE html>
<html lang="en>
<head>
    <meta charset="UTF-8>
    <title>TEST</title>
<script type="text/javascript" src="https://externalsite.com/script.js" async=true>
</script>

</head>
<body>

    <p>
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. ... [truncated for brevity]
        
    </p>;

</body>
</html>

A JS file hosted on an external site modifies the page by displaying a div in the center with two buttons.

<!DOCTYPE html>
<html lang="en>
<head>
    <meta charset="UTF-8>
    <title>TEST</title>
<script type="text/javascript" src="https://externalsite.com/script.js" async=true>
</script>

</head>
<body>
<div class="qc-cmp-ui-container qc-cmp-showing">
   <div class="qc-cmp-ui qc-cmp-showing" id="qcCmpUi">
      ... [truncated for brevity]
   </div>
</div>
</body>
</html>

The aim is to hide the div with the class qc-cmp-ui-container.

I attempted to use jQuery:

document.addEventListener("DOMContentLoaded", function(event) {
    console.log("DOM loaded and parsed");
    $('.qc-cmp-ui-container').hide();
  });

However, the div remains visible. How can I successfully hide it?

Answer №1

It's important to note that you should not try to hide a div before it has been created. The DOMContentLoaded event is triggered when the DOM is fully loaded, not when its content is changed. To ensure that the div is properly hidden, wait for it to be created and then apply the hide function.

var interval = setInterval(function(){
    if($('.qc-cmp-ui-container').length) {
        $('.qc-cmp-ui-container').hide();
        clearInterval(interval);
    }
}, 150);

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

Retrieve Checkbox within a Span using Jquery

Trying to achieve the selection of a checkbox when a user clicks on a div using jQuery. The provided fiddle shows my attempt: http://jsfiddle.net/5PpsJ/ The code snippet I have written so far is as follows, but it doesn't seem to select the checkbox ...

Integrating Facebook login into a website running on localhost

Within my index.php file, the code includes: <div id="fb-root"></div> <script type="text/javascript"> window.fbAsyncInit = function () { FB.init({ appId: '<?php echo $appId; ?>', cookie: true, ...

Require modification of JSON values in React Promise code

Looking to modify the data returned from a promise and wrap a link around one of the fields. Here is the React code: this.state = { medications: [], } queryMeds().then((response) => { this.setState({medications: response}); }); The response c ...

Using Typescript to set a custom timeout duration based on a dynamic variable within a for loop

My function includes a timeout that changes every 3 seconds: setActiveImage(promotions) { for (let i = 0; i <= promotions.length - 1; i++) { setTimeout(()=> { this.activeImage = 'http://myrul/public/Commercials/' + promo ...

Ensure to insert placeholder functions before executing the script as a child process

Typically, mocks and stubs are utilized in automated testing scenarios. However, I am interested in stubbing methods for manual testing of my application. This approach would allow me to run my server and manually test my app in the browser. For example, w ...

Effortless 'rotational' script

I am currently developing a HTML5 Canvas game with the help of JavaScript. My aim is to create an object that smoothly transitions to a specific direction. The direction is being stored as a variable and calculated in radians. Here's how the code op ...

Make sure to include crossorigin="anonymous" in all img tags before the images start loading

I am currently facing issues with my canvas displaying errors due to cached images causing CORS policy errors. The solution I am considering is adding crossorigin="anonymous" to all the images on my website. However, I am unsure of how to impleme ...

Dead keyup event using jQuery live in SignalR invocation

I am working on a sample chat application using SignalR, but I'm facing an issue with my keyup event not functioning properly. Below is the code snippet: // Keyup event for text box $(".ChatText").on('keyup', function () { if($(".ChatTe ...

Utilizing the power of jQuery.each() in a connected series

I want to populate newly created HTML elements with results from an object: *long chain of newly created elements*.append( $("<div />").append( $.each(myObj.results, function( intIndex, objValue ){ return objValue.description ...

Ways to verify if options have been chosen or not?

if(isset($_POST["marketing"])){ foreach($_POST as $key => $value){ if(strlen($value)<1) continue; echo "<option value='".$value."' selected >".$value."</option>"; } I have a PHP script that dynamically cre ...

Angular - Exploring the Dynamic Validation of Multiple Fields Across Components

Currently in the process of developing a classifieds site using Angular. The main component of the route is structured as follows: Contains static fields (name, email, phone, location, etc.) defined in its template Includes a dynamically loaded compo ...

Unexpected Quote Will Not Appear

My random quote generator is not functioning properly, it should display a different quote on each click of the button. My colleagues are also facing the same issue. It was working fine when implemented in JavaScript, but after converting all the syntax to ...

Tips for Adjusting the Size of a Search Bar

I've encountered an issue with a form I was developing. I decided to start fresh on an old project that included recreating the Google homepage design. While I aimed for an exact replica, some elements were unnecessary. The search box (form) moved to ...

Choose the ngModel option from the dropdown menu

I have a project where I need the first question from a list to be displayed automatically. I found an example of how to do this using the index, like so: <select> <option *ngFor="let answer of answers; let i = index" [value]="answer.id" [selec ...

The peculiar formatting issue with the jQuery datepicker that arises when adding more months

When adjusting the numberOfMonths parameter to a higher value such as 6, I noticed that the datepicker display appears unusual with the background extending further than expected. Take a look at my demonstration on jsfiddle: http://jsfiddle.net/zw3z2vjh/ ...

Adjust the color of the border surrounding the icon within a button

Is there a way to customize the color border of an SVG icon within a button to match the text of the button? My code snippet can be found on JSFiddle, along with my usage of Bootstrap: JSFiddle @import 'https://maxcdn.bootstrapcdn.com/bootstrap/4 ...

What is the best way to prevent users from clearing the value attribute of an input element?

Sample Scenario: While a user is entering information into a field, I would like to restrict the ability to delete or clear out the value, such as keeping "Friend" intact. Can this be accomplished using CSS or JavaScript? ...

Comparison of Static Site Generation (SSG) with Server-Side Rendering and Client-Side Rendering

The lack of concrete information surrounding the inner workings of Client-Side Rendering (CSR), Server-Side Rendering (SSR), and Static Site Generation (SSG) is truly perplexing to me. Despite numerous articles that vaguely touch on these concepts, I have ...

Docz: Utilizing Typescript definitions for props rendering beyond just interfaces

We are currently using Docz to document our type definitions. While it works well for interfaces, we've run into an issue where rendering anything other than interfaces as props in Docz components doesn't seem to display properly. I'm seeki ...

Is it necessary for me to use a .jsx extension when saving my React component files?

After working with React for a few months, I recently noticed that some of my files have the .js extension while others have the .jsx extension. Surprisingly, when I write JSX code in the .js files, everything still functions correctly. Is there any signif ...