简体   繁体   中英

What are the reasons or benefits of using dynamic id in each and every html elements

Recently I found one website in which, all the html elements have dynamic id's. This website is very popular in the world.(www.quora.com)

Now I just want to know that what is the reason to do this type of stuff for all the html elements which are available on web pages.

I actually don't see that in the Quora source served to me. There are a lot of ids but they are all in <g> elements that form part of svg graphics.

Looking at the browser's view of the (signed in) homepage via Chrome's inspect tool I only see four ids.

In general if I saw ids on most/all elements in a page I'd expect a framework being used to generate the HTML.

useally its a side-effect of the framework people are using for the website.

The reason it is used at all tho is because a single webpage can't have duplicate id's, this because if this would happen the browser would not know witch element to pick with the givin id. when you try this out yourself you would notice the browser only picking the first element with the given id. the other elements with the same id will be ignored or the code will not run at all.

A solition to this problem is dynamicly adding the id's so you can reference to those elements without the risk of some elements being ignored.

By dynamicly adding these id's you can be certain that every id will be diffrent from each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM