dynamic
dynamic

Reputation: 48101

Adding attribute to html tag?

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">

Upvotes: 3

Views: 292

Answers (3)

m.edmondson
m.edmondson

Reputation: 30882

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

Upvotes: 0

Goran Genter
Goran Genter

Reputation: 159

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

document.getElementById("txtBox").getAttribute("mycustomvalue");

Upvotes: 0

SLaks
SLaks

Reputation: 887453

Yes, you can do that.

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

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

Upvotes: 10

Related Questions