首页 > 解决方案 > About DOM elements internal indentifier

问题描述

I'd like to identify univocally some DOM elements (specifically, the <li> elements of an <ul> list). First, I thought about using the id or data- attributes, but I declined the option because these attributes can be changed easily using the developer tools.

Is there any internal id that I could use for this purpose?

Thanks!

标签: javascripthtmldom

解决方案


There is no internal ids for elements. There is no way to really set an id on an element that can not be changed.

Only thing you really can do is hold references to elements in an array/object/variables, but even a person could set a break point in the code and alter that.

So in the end, there is really no way to identify an element and not have a person muck in developer tools and change it.


推荐阅读