Are buttons continuously added on top of each other?

It seems that the root of my problem lies in my use of ng-repeat, so I won't go into too much detail on the rest but feel free to ask for more information.

Indeed, I am employing ng-repeat to iterate over a certain number of div elements stored in an array.

Each time I create a new div and add it to the array...

var newDiv = document.createElement('div');
$scope.arrayDiv.push(newDiv);

...I also insert a button (which, in reality, is an image) and attach it to the div.

var newButton = document.createElement('img');
newButton.style="position: absolute; top: 6px; left: 16px; z-index: 9999;";
newButton.onclick=function() {
    //delete the parentNode
}
newDiv.appendChild(newButton);

This button essentially serves as a close button to remove the containing div. Everything seems to be working fine, but here's the catch:

The close button only appears on the first div, not on the others. Nonetheless, the button is able to close the divs one by one. This suggests that the buttons may be overlapping.

I hope that clears things up. Here is the ng-repeat block I mentioned:

<div id='main_chart_div' ng-repeat="x in arrayDiv" value={{x}}></div>

Answer №1

Ensure that your customDiv is positioned relative. Failure to do so will result in the positioning of the customButton being relative to its nearest parent with a relative position.

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

Tips for guaranteeing that HTML elements maintain distinct ids when duplicated within a design

Looking for a solution to ensure unique IDs in a piece of HTML code within a DTL for loop. {% for job in work_experience %} <div class="work-exp-item"> <h4 id="exp-title" class="body-text">{{ job.title }}</h4> <h5 id="exp-comp ...

Is there a javascript file storing an image?

Currently, I am in the process of creating my personal portfolio website and incorporating react-bootstrap for designing my react components. I have been attempting to add an image using the Image component provided by react-bootstrap. However, I noticed ...

Can you explain the significance of "javascript:void(0)"?

<a href="javascript:void(0)" id="loginlink">login</a> The usage of the href attribute with a value of "javascript:void(0)" is quite common, however, its exact meaning still eludes me. ...

Connecting Vue.js components together

I have two separate components - one for viewing data and another for editing the same data. The viewing component contains labels and paragraphs, while the editing component includes inputs and textareas. Both components are fed the same data object. Is ...

Communication between AngularJS directives and controllers occur when a function is called upon a change

I have developed a unique custom directive which is defined as: <div class="col-md-6"> {{templateMapping[colProp].SheetPointer}} <select class="form-control" ng-model="selectedColumn" ng-change="changeMapping()" ng ...

Sending a prop to a handler causes issues with navigation paths

I'm facing an issue with my handler and button component setup. Here's my handler: const addToCartHandler = (id) => { navigate(`/cart/${brand}/${id}?qty=${qty}`)}; And here's the button component using the handler: <Button onClick={a ...

Sending a object as an argument to a function

Could someone please help me understand the purpose of passing an object as a function parameter? I have been trying to learn Next.js and they frequently use this method in their code. If anyone could provide a brief explanation of why this is done, it wo ...

generate a variety of react checkboxes based on a JavaScript object

I currently have an object in the state that holds the current value of four 'Risk Type' checkboxes riskTypes: {"Fraud": true, "Steal": true, "Scam": true, "Theft": true}, When rendering the subcomponent t ...

show fixed div when in view

After seeking inspiration from this specific thread on SO, I still need some help. The challenge I'm facing involves displaying a sticky footer within a parent div that is positioned halfway down the page. I've tried multiple tutorials, but none ...

The $http get request in AngularJS functions properly in Chrome but unexpectedly returns null in FireFox

My MVC app utilizes AngularJS without the use of WebAPI. The AngularJS makes calls to the MVC Controllers which work perfectly in IE and Chrome. However, I have been struggling for hours to make it work in Firefox and Safari without any success. The code s ...

Display an array in Angular HTML by calling a function

I am currently working on an app that involves displaying cars retrieved from a database. Each car has a string of tags separated by commas, and I have created a function to split these tags into individual words and display them as tags. However, I am str ...

AngularJs: A discrepancy between directive scope update and controller scope update

I am experiencing a problem with AngularJS. I have developed a factory and a directive for an input field. The issue arises when the value of the input changes in the directive - I want to update the controller value at that moment, but there seems to be a ...

Develop a TypeScript class by incorporating a static function from an external library, while ensuring type safety

I am looking to enhance the capabilities of the rxjs5 Observable class by adding a static function. While this can be easily accomplished in plain JavaScript: var myStaticFn = function() { /* ... */ }; Observable.myStaticFn = myStaticFn; this approach w ...

Retrieve a pair of columns from the database by utilizing SQLalchemy

Currently, I am delving into Python and endeavoring to generate a drop-down menu within my form by utilizing data from another table. Here is the code snippet I have been working on: In my Models.py file: class empmasterModel(db.Model): __tablename__ ...

Steps to update the action attribute in a form element upon clicking a button

Within the following code snippet, there are 3 buttons - update, back, and delete. Depending on which button is clicked, the $page variable should be assigned to the action attribute in the form element, with the posted data being sent accordingly. <f ...

AJAX error encountered: TypeError - the properties 'arguments', 'callee', and 'caller' are inaccessible in the current context

While conducting an API call on a particular system, I encountered an error. Interestingly, I am able to obtain a response using curl and Postman with the same URL; however, Safari throws this error when employing Angular's $http.get() method. The is ...

What is the code for a non-breaking space in a JavaScript string?

It seems that this code is not functioning as expected: text = $td.text(); if (text == '&nbsp;') { text = ''; } Could it be related to a non-breaking space or the ampersand causing issues in JavaScript? ...

Sending a form without the need to reload the page

While it's known that Ajax is the preferred method to submit a form without refreshing the page, going through each field and constructing the Post string can be time-consuming. Is there an alternative approach that utilizes the browser's built-i ...

PHP is sending incomplete email messages

After implementing a PHP script to send an email upon unsubscribing, I encountered an issue where only part of the email was being sent. Here is a JSFiddle example that represents how the complete email should look, although it may not appear neat due to b ...

Unable to convert the BSON type to a Date in MongoDB

I am currently facing an issue while attempting to filter data stored in MongoDB utilizing parameters from the URL. Whenever I send the request, the server crashes and displays the error message: can't convert from BSON type string to Date I attemp ...