0

Is it really not possible to get all the attributes inside an html tag with jQuery in a simple way? For instance if I have the following element

<div id="1" class="myclass" height=200 data-js-reload="20">

I would like to get a string containing id="1" class="myclass" height=200 data-js-reload="20"

Haven't been able to find an elegant solution for such a "simple" problem. I tried looking into the data() function, but didn't quite seem to be what I was looking for.

  • The duplicate has your answer, although I would ask why you feel the need to do this. Accessing attributes in this manner is normally a code smell, indicating a problem which can normally be solved in a much more elegant way. – Rory McCrossan Jul 19 '22 at 20:10
  • Saw that one, 9 years old, a lot have changed since, so figured there was a better way to do this today. Replacing an element type, which strips the attributes. – Michael Nielsen Jul 19 '22 at 21:16

0 Answers0