# Get Div Class with Javascript

**URL:** <https://forum.bubble.io/t/get-div-class-with-javascript/240099>\
**Category:** Questions\
**Created:** [January 6, 2023, 12:16pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099 "2023-01-06T12:16:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramasuarez](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ramasuarez/32/181820_2.png) [@ramasuarez](https://forum.bubble.io/u/ramasuarez)\
**Post date:** [January 6, 2023, 12:16pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099/1 "2023-01-06T12:16:26Z")

</div>

Hi there!

I’m trying to get information from a class with javascript executing the parameter document.getElementsByClassName(“className”); without any lucky.

This is the real case:

```
<div id="uploadcare--widget __text" class="uploadcare--widget__ text" aria-live="polite">
**<div class="uploadcare--link uploadcare--widget__file-name" tabindex="0" role="link">1 (1).mp4</div>**

```

I added the following code with the toolbox pluging - javascripttoBubble in page:

`bubble_fn_1(document.getElementsByClassName("uploadcare--link uploadcare--widget__file-name").value)`

Calling a Div Id I didn’t have any issues.

Note1: I found this solution from the post of **@mebeingken** ([[SOLVED] Get data from HTML Element](http://forum.bubble.io/t/solved-get-data-from-html-element/47994)). Thank you!  
Note2: I didn’t find any post with this trouble.

Any ideas? 🙏

Cheers.

---

<div class="post-metadata">

**Author:** ![exception-rambler](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/exception-rambler/32/152704_2.png) [@exception-rambler](https://forum.bubble.io/u/exception-rambler)\
**Post date:** [January 6, 2023, 1:43pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099/2 "2023-01-06T13:43:46Z")

</div>

`getElementsByClassName` returns an array whereas `getElementById` returns a single value.  
Try adding `[0] ` to the return value to access the first item in that array: `document.getElementsByClassName("uploadcare--link uploadcare--widget__file-name")[0]`

---

<div class="post-metadata">

**Author:** ![ramasuarez](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ramasuarez/32/181820_2.png) [@ramasuarez](https://forum.bubble.io/u/ramasuarez)\
**Post date:** [January 6, 2023, 2:13pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099/3 "2023-01-06T14:13:39Z")

</div>

Thank you for your response! I tried but I still without getting the text.

---

<div class="post-metadata">

**Author:** ![exception-rambler](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/exception-rambler/32/152704_2.png) [@exception-rambler](https://forum.bubble.io/u/exception-rambler)\
**Post date:** [January 6, 2023, 2:36pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099/4 "2023-01-06T14:36:33Z")

</div>

I’m not sure what `.value` does in your example?  
As far as I know it’s not something that’s included as part of the return from `getElementsByClassName()` method. Where does that come from?

Check out this simple example [here](https://codepen.io/edbutcher/pen/qByqybe) of what I think you’re trying to do.

---

<div class="post-metadata">

**Author:** ![ramasuarez](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ramasuarez/32/181820_2.png) [@ramasuarez](https://forum.bubble.io/u/ramasuarez)\
**Post date:** [January 6, 2023, 5:26pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099/5 "2023-01-06T17:26:57Z")

</div>

@exception-rambler I don’t know the reason of “.value”, I took it from the original post of this issue.  
I test different alternatives from the browser console and I found the solution execution this:

`document.querySelector('.uploadcare--widget__file-name').textContent;`

By the way, I got the response from ChatGPT.

Thank you @exception-rambler.

---

<div class="post-metadata">

**Author:** ![julienallard1](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@julienallard1](https://forum.bubble.io/u/julienallard1)\
**Post date:** [January 8, 2023, 1:31pm UTC](https://forum.bubble.io/t/get-div-class-with-javascript/240099/6 "2023-01-08T13:31:03Z")

</div>

ChatGPT is scary good…

I’m just adding my 2 cents here: `textContent` gets the content of all elements, including `<script>` and `<style>` elements. In contrast, `innerText` only shows “human-readable” elements. In general it is better to use `innerText`.
