I have the following code:
<div id="elm0" data-color="color" data-size="size" data-more="more">something</div>
<div id="elm1">This element must get elem0 attr</div>
I know that I can get $(“#elm0”).attr(“color”) in a var and pass it to $(“#elm1”) but in my case I do not know exactly what attributes are there. I am looking for something that does:
get all attr from $(“#elm0”) and pass
them to $(“#elm1”)
How can I do this?
Thanx
Edit: I need to get only HTML5 data attributes like data-color=”color”, data-size=”size” not class, ID, style…
You could do something like this in vanilla JavaScript:
You can give it a try here, or…in plugin form!
You would call it like this:
You can test that version here.