DEV Community

Haryniramesh
Haryniramesh

Posted on

FUNCTIONS IN JAVASCRIPT

1.document.getElementsByClassName(className);

  • It returns a live HTML Collection,if the DOM changes the HTML Collection will automatically update.

  • It returns a collection of elements with the given class name, so we need to loop them.

  • If no elements match, it returns an empty HTML Collection.

2.document.getElementsByTagName(tagName);

  • It returns a live HTML Collection, meaning if the document is updated the HTML Collection will be updated automatically.

  • It matches all elements with the specified tag name, and you can loop through the returned collection or access specific elements by index.

  • If no elements match, it returns an empty HTML Collection.

3.Math.sqrt(x);

  • The square root function is only defined for non-negative real numbers, so passing a negative number to Math.sqrt() will return NaN.

  • For complex numbers JavaScript does not directly handle them using Math.sqrt(). You would need a different approach or library for that.

4.Math.abs(x);

  • It is a built-in method that returns the absolute value of a number.

  • The absolute value of a number is its non-negative value, meaning it removes any negative sign.

5.document.getElementById(id);

  • It is a built-in method used to retrieve an element from the DOM by its ID attribute.

  • This method is one of the most common ways to interact with specific elements in an HTML document.

6.document.write(text);

  • It is a method used to write text or HTML content directly to the document during the page's loading process.

Top comments (0)