Level no.25

 Java-Script

Lecture #3

Q. What is the purpose of .innerHTML, .value and .textContent in java-script?

.innerHTML, .value and .textContent are not used for same purpose in java-script, they serve different roles when working with HTML elements. They might have similar syntax because they are properties of   DOM elements in HTML, DOM stand for Document Object Model. 

1. .innerHTML:

This property is used to get or set the HTML content within an element. You can use this to retrieve 

the HTML content inside an element or to change it by assigning new HTML content to it.


2. .value:

This property is used with for elements like input fields, checkbox and radio buttons  to get or set their current values. You can use this to retrieve the current value of the input fields or to  set a new values, you can get or set the input fields values through java-script.


3. .textContent:

This property is used to get or set the text content of the element. You can use this property to retrieve the plain text content of an element or to replace it with  new plain text. it is useful when you want to work with text content of an element without considering the HTML structure.

 

 



Comments

  1. I am always confused with DOM elements. Thank you for clearing my concept

    ReplyDelete
  2. Well explained, keep it up.

    ReplyDelete

Post a Comment

Popular posts from this blog

Level no.4

Level no.21

Level no.3