Q
What is the advantage of using CSS classes to hide HTML elements compared to inline styles in JavaScript?

Answer & Solution

Answer: Option B
Solution:
Using CSS classes to hide HTML elements in JavaScript offers the advantage of better separation of concerns and reusability. CSS classes can be defined once and applied to multiple elements, improving code maintainability and reducing redundancy.
Related Questions on Average

How can you hide an HTML element using JavaScript by modifying its display property in an external CSS file?

A). element.style.display = 'none';

B). Add an external CSS file to the HTML document and link it.

C). Use the classList property to add a class with hidden properties.

D). element.classList.add('hidden');

How can you hide an HTML element using JavaScript by modifying its visibility property?

A). element.style.display = 'none';

B). element.visibility = 'hidden';

C). element.style.visibility = 'hidden';

D). element.style.display = 'hidden';

What happens to an HTML element when its display property is set to 'none' using JavaScript?

A). It is removed from the DOM.

B). It becomes invisible but still occupies space in the layout.

C). It becomes visible but disabled.

D). It becomes hidden but still interacts with the layout.

How can you hide an HTML element using JavaScript by applying an external CSS class?

A). element.style.display = 'none';

B). Add an external CSS file to the HTML document and link it.

C). Use the classList property to add a class with hidden properties.

D). element.classList.add('hidden');

How can you hide an HTML element using JavaScript by modifying its CSS class?

A). element.style.display = 'none';

B). Add an external CSS file to the HTML document and link it.

C). Use the classList property to add a class with hidden properties.

D). element.classList.add('hidden');

Which property is commonly used in JavaScript to hide an HTML element without removing its space in the layout?

A). visibility

B). hidden

C). display

D). none

How can you hide an HTML element using JavaScript without affecting its space in the layout?

A). element.style.display = 'none';

B). element.visibility = 'hidden';

C). element.style.visibility = 'hidden';

D). element.style.display = 'hidden';

How can you hide an HTML element using JavaScript by toggling its visibility state?

A). element.style.display = 'none';

B). element.style.visibility = 'hidden';

C). element.style.visibility = 'toggle';

D). element.toggle('hidden');

How can you dynamically hide an HTML element using JavaScript based on a button click event?

A). element.style.visibility = 'hidden';

B). element.display = 'none';

C). element.style.display = 'none';

D). element.visibility = 'hidden';

Which JavaScript method is commonly used to hide an HTML element by adding a CSS class with hidden properties?

A). element.style.visibility = 'hidden';

B). element.classList.add('hidden');

C). element.style.display = 'none';

D). element.classList.toggle('hidden');