189 of 264 menu

hasAttribute method

The hasAttribute method checks if an element has a given attribute. If the attribute is present, it will output true, if not, it will output false.

Syntax

element.hasAttribute(attribute name);

Example

Let's check for the presence of the value attribute on an element:

<input id="elem" value="abcde"> let elem = document.querySelector('#elem'); console.log(elem.hasAttribute('value'));

The code execution result:

true

Example

And now there is no the value attribute:

<input id="elem"> let elem = document.querySelector('#elem'); console.log(elem.hasAttribute('value'));

The code execution result:

false

See also

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline