I used
element.hasAttribute('id')
in my code to check if an element has an id attribute . But hasAttribute API is only compatible with browsers after IE8. There is a similar API or method that I can use to check the availability of the attribute for the element in my case, "id".
Just check element.id- it will be an empty string if it is not installed.
element.id
There is no need to use element.hasAttributefor those attributes that are reflected by the properties of the JS object.
element.hasAttribute
hasAttribute getAttribute. null, , - . , , .
hasAttribute
getAttribute
null
if ((element.getAttribute('id') === null) || (element.getAttribute('id') === '')) {