开发者

Adding attribute to html tag?

开发者 https://www.devze.com 2023-02-19 17:10 出处:网络
for internal reasons I need to attach some information to some html tag. Example: <img src=\"mypic\" mycustomvalue=\"abc\">

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开发者_JS百科 or there is another way?

Thanks

I am currently using HTML 5

<!DOCTYPE html><html lang="en">


Yes, you can do that.

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

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


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消