Languages
[Edit]
EN

JavaScript - hasAttribute() method example

0 points
Created by:
a_horse
538

In this article, we would like to check if the element has attribute using hasAttribute() method in JavaScript.

Quick solution:

Where:

  • element - the element we want to check if it has a given attribute,
  • attributeName - name of the attribute we want to check if exists.

 

Practical example

Edit

In this example, we will check if myDiv element has class and onclick attributes using hasAttribute() method.

Alternative titles

  1. JavaScript - has attribute method example
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join