# Http - Parse value of an element attribute? (DOM getAttribute())

**URL:** <https://discourse.nodered.org/t/http-parse-value-of-an-element-attribute-dom-getattribute/50530>\
**Category:** General\
**Created:** [2 September 2021 08:12 UTC](https://discourse.nodered.org/t/http-parse-value-of-an-element-attribute-dom-getattribute/50530 "2021-09-02T08:12:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TottiT](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TottiT](https://discourse.nodered.org/u/TottiT)\
**Post date:** [2 September 2021 08:12 UTC](https://discourse.nodered.org/t/http-parse-value-of-an-element-attribute-dom-getattribute/50530/1 "2021-09-02T08:12:30Z")

</div>

Hey there!

I'm looking for a clean way to get the value of an attribute in an HTML element, similarly as the getAttribute() function [\*] would allow. Is there something in node-red that would provide similar functionality? At the moment getting the value of an attribute requires me writing some specific javascript string-matching, which doesn't feel so clean.

\*[Element.getAttribute() - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute)

Put another way, how would you extract the URL from an HTML element similar as below?

```auto
<img src="https://something.interesting.com" alt=\"210103_1\">

```

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 September 2021 08:56 UTC](https://discourse.nodered.org/t/http-parse-value-of-an-element-attribute-dom-getattribute/50530/2 "2021-09-02T08:56:32Z")

</div>

Assuming you mean in node-red (and not client side)...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/757e72c94acaf1d42f5f22291cdae1656a3fcd12.png)

```auto
[{"id":"dab3993734b39446","type":"inject","z":"eb3bd3ff.33367","name":"<img src=\"https://something.inte...","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<img src=\"https://something.interesting.com\" alt=\\\"210103_1\\\">","payloadType":"str","x":1960,"y":100,"wires":[["0c5f6a136547526b"]]},{"id":"0c5f6a136547526b","type":"html","z":"eb3bd3ff.33367","name":"","property":"payload","outproperty":"payload","tag":"img","ret":"attr","as":"single","x":1990,"y":160,"wires":[["e1196d058c5e8456"]]},{"id":"e1196d058c5e8456","type":"debug","z":"eb3bd3ff.33367","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2030,"y":220,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![TottiT](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@TottiT](https://discourse.nodered.org/u/TottiT)\
**Post date:** [2 September 2021 13:05 UTC](https://discourse.nodered.org/t/http-parse-value-of-an-element-attribute-dom-getattribute/50530/3 "2021-09-02T13:05:36Z")

</div>

Thanks a lot @Steve-Mcl, that did it! I think I even tried the "object of attributes"-option in the HTTP-parser at some point, but it was only giving me empty arrays.. I must have had the CSS selector wrong, damn it I should tried harder. Anyways, thanks again!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 September 2021 13:06 UTC](https://discourse.nodered.org/t/http-parse-value-of-an-element-attribute-dom-getattribute/50530/4 "2021-09-16T13:06:08Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
