3

for internal reasons I need to attach some information to some html tag. Example:

<img src="mypic" mycustomvalue="abc">

Can I add safely like that or there is another way?

Thanks

I am currently using HTML 5

<!DOCTYPE html><html lang="en">
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
dynamic
  • 46,985
  • 55
  • 154
  • 231

3 Answers3

10

Yes, you can do that.

Note that the HTML5 standard is to prefix custom attributes with data-:

<img src="mypic" data-mycustomvalue="abc">
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Yes, you can set it like that, and retrieve it with :

document.getElementById("txtBox").getAttribute("mycustomvalue");
Goran Genter
  • 159
  • 4
0

Use getAttribute(), this should allow you to retrieve the value of any attribute.

m.edmondson
  • 30,382
  • 27
  • 123
  • 206