# Get the respective button value in a loop

**URL:** <https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832>\
**Category:** UXP Plugin API\
**Created:** [February 10, 2023, 4:46pm UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832 "2023-02-10T16:46:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MalbertCunha](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/malbertcunha/32/2760_2.png) [@MalbertCunha](https://forums.creativeclouddeveloper.com/u/MalbertCunha)\
**Post date:** [February 10, 2023, 4:46pm UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/1 "2023-02-10T16:46:18Z")

</div>

Hello! Trying to add a group of dynamic buttons here from an array, the return of querySelectorAll does not seem to get the list of values. Where am I going wrong? Thanks  
Here my code:  
html:

```auto
<div id="container"></div> 

```

js:

```auto
const btns = document.getElementById("container");
const textBtn = ["btn 1", "btn 2", "btn 3", "btn 4", "btn 5", "btn 6"]
for(i=0; i <textBtn.length;i++){
btns.insertAdjacentHTML('beforeend', `<sp-action-button class="allbuttons" value="${textBtn[i]}">${textBtn[i]}</sp-action-button>`);  
}

const btn = document.querySelectorAll(".allbuttons")
    for (var i = 0; i < btn.length; i++) {
        btn[i].addEventListener('click', function (event) {
        //console.log( btn[i]);
        console.log( event.target.value);
        alert(event.target.value)
    });
}

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [February 10, 2023, 9:54pm UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/2 "2023-02-10T21:54:07Z")

</div>

Did you check in console what you get for `btn`? Are your buttons inserted where you expect them to be? Did you try to inspect what’s your HTML after `insertAdjacentHTML()` loop?

---

<div class="post-metadata">

**Author:** ![MalbertCunha](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/malbertcunha/32/2760_2.png) [@MalbertCunha](https://forums.creativeclouddeveloper.com/u/MalbertCunha)\
**Post date:** [February 11, 2023, 1:05am UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/3 "2023-02-11T01:05:16Z")

</div>

Hi @Karmalakas thanks for answering, in console all the buttons look correct but return undefined.

 ![Capturar](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/2/22fe5194f1503573266b0ccc0207f2aca7bd520e.png)

---

<div class="post-metadata">

**Author:** ![MalbertCunha](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/malbertcunha/32/2760_2.png) [@MalbertCunha](https://forums.creativeclouddeveloper.com/u/MalbertCunha)\
**Post date:** [February 11, 2023, 1:16am UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/4 "2023-02-11T01:16:28Z")

</div>

Before starting some UxP projects, I perform some tests in the chrome browser and everything works fine, but without success with the UXP plugin

 ![Capturar](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/7/79f56124553d802abdd9a6350524cfb04797c458.png)

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [February 11, 2023, 11:29am UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/5 "2023-02-11T11:29:32Z")

</div>

**!!! UXP is NOT Chrome !!!**  
UXP probably doesn’t have half of what Chrome has

Having said that, it works here:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/c/cee6023e7228e7cc13fa48a16bcf6783af2cc931.png)

Probably in UXP you can’t get `Node.value` directly and need to access it via attributes

---

<div class="post-metadata">

**Author:** ![MalbertCunha](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/malbertcunha/32/2760_2.png) [@MalbertCunha](https://forums.creativeclouddeveloper.com/u/MalbertCunha)\
**Post date:** [February 11, 2023, 12:04pm UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/6 "2023-02-11T12:04:30Z")

</div>

1- I’m on my cell phone, I haven’t tested it yet, I saw from the print that you found the solution that makes me very happy and grateful.  
!!! UXP is NOT Chrome!!!  
2 - Yes, I know that, I believe that I, like many here who started in UXP, are migrating from CEP, many of these javascript codes work perfectly in internet browsers as well as in CEP panels.  
That said, it’s much easier for you to create a .html file and test some functionality than having to create a UXP plugin for that.  
3 - Is this plugin that you use for debugging available in some repository or is this just your domestic resource?  
!!!THANKS FOR THE SOLUTION!!!

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [February 11, 2023, 12:48pm UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/7 "2023-02-11T12:48:07Z")

</div>

> [@MalbertCunha](#):
>
> Is this plugin that you use for debugging available in some repository

It’s [UI Playground](https://github.com/AdobeDocs/uxp-photoshop-plugin-samples/tree/main/ui-playground) - one of [sample plugins](https://github.com/AdobeDocs/uxp-photoshop-plugin-samples/). I saw months ago @kerrishotts was using some updated version, but this public one hasn’t been updated in years 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![MalbertCunha](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/malbertcunha/32/2760_2.png) [@MalbertCunha](https://forums.creativeclouddeveloper.com/u/MalbertCunha)\
**Post date:** [February 11, 2023, 12:52pm UTC](https://forums.creativeclouddeveloper.com/t/get-the-respective-button-value-in-a-loop/5832/8 "2023-02-11T12:52:12Z")

</div>

@Karmalakas Thanks again. This weekend I’m going to dive into the studies, UXP is wonderful. A big hug friend and until my next post
