Fork me on GitHub
#beginners
<
2023-02-26
>
M J10:02:44

How can I get the element by id of a div element, for example, I have:

<div aria-hidden="false">
<div id="id-10822"></div>
</div>
I would like to getElementById of the "id-10822", then gets its parents "aria-hidden" value

phill10:02:48

You may use whichever of the browser's built-in functions you would use in Javascript. Remember the getElementById is a function on the DOM Document, which in ClojureScript can be referenced as js/document. So you can start with (.getElementById js/document "id-10822")

👍 1
kennytilton10:02:11

...and as a lucky CLJS user, you can also use https://google.github.io/closure-library/api/goog.dom.html :

(goog.dom/getElement "id-10822")

kennytilton14:02:12

Oops. Missed the rest of the Q. Once you have the div, this gives you the parent:

(.-parentNode div) or (goog.dom/getParentElement div)
Once you have the parent, this gives you "aria-hidden":
(.-ariaHidden parent) or (goog.object/get parent "ariaHidden")