Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
New coder here I need help wording what i need so i can better understand what im trying to accomplish. I revised my question to try better explaining what im after!

The JavaScript code has an array of objects that gets iterated over to create a div for each index in the array myArray[i];
This function creates a div for each of the objects in the array and sets the id for each of the objects in that array from the object.name or object.id when i run the code

now the html has a container div with the (x) number of divs that were in the array.

Now What im trying to accomplish is if i now click on the div that was created dynamically how can i change Do something to the "myArray[i]" that was just clicked
it self

What I have tried:

what i have tired is using even.target to get the div thats clicked that works but its returning a dom element in the console so it event.target does tell me and i can do stuff with the html element but what i need is to wire that was clicked to the this.myArray[i] that was clicked

i have tried the getElementsByClassName and i get a html collection

i have tried the queryselectorAll i get a node list

so my question is what is the best way to wire an array of objects to an event click so that i can remove the div that was click from this array for example and Not from the dom but from the array



what i can do is move it to a different container or from the dom all together but cant seem to find a way to wire the html collection or nodelist direct to the array

Like do i need to iterate over the html collection or node list and set html collection or nodelist to = to the myArray[i]

sorry i have a hard time explaining anything in life :)
any direction would be appreciated!
i did not include my code as this is a question in direction two or 3 key words can easily lead me down the right path
Posted
Updated 5-Apr-20 2:13am
v2

1 solution

Try giving proper description of container_div. Write the html of container_div here so that problem can be evalvated easily. Furthrmore try getting your id first for when you click on the button it should first alert its id so that you make sure that the proper id has been bind
 
Share this answer
 
Comments
Member 14792643 5-Apr-20 8:31am    
the word bind may have put me on the right path thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900