1.

What is the difference between attribute and property?

Answer»

Attributes are an element of an HTML document while properties are a part of the Document Object Model (DOM).

Example: <input type="TEXT" value="Tech">

Here, value and type are the attributes of HTML, but when the statement is READ by the browser and parses this code it will make a DOM with DIFFERENT properties, like accept, autofocus, ACCESSKEY, baseURI, checked, childElementCount, align, alt, childNodes, children, classList, className, attributes, and clientHeight.

Example:

var data = document.querySelector(input); // here we created a document object of input tagconsole.log(input.getAttribute('value')); // tech // getting the attribute valueconsole.log(input.value); // tech // getting the property of the input object


Discussion

No Comment Found