How to find duplicate id's in a form?

后端 未结 6 2617
无人及你
无人及你 2021-02-20 13:16

I\'ve created a form with about 800 fields in it. Unknowingly I\'ve given same id for few fields in the form. How to trace them?

6条回答
  •  长情又很酷
    2021-02-20 13:54

    One-ish liner using just array methods:

    [].map.call(document.querySelectorAll("[id]"), 
         function (e) {
            return e.id;
         }).filter(function(e,i,a) {
            return ((a.lastIndexOf(e) !== i) && !console.log(e));
         })
    

    Logs every duplicate and returns an array containing the ids if any were found.

提交回复
热议问题