How to Remove HTML Element Attribute using Javascript

I had to remove a HTML element on page unmount in React and I came to know about removeAttribute() method. Let鈥檚 have look at this. Syntax node.removeAttribute(attrName); // node is nothing but an element whose attribute has to be removed Return value is undefined Parameters A string specifying the name of the attribute to remove from the element. If the specified attribute does not exist,removeAttribute() returns without generating an error....

August 14, 2022 路 1 min 路 Mohammad Shahzaib

How to Check if Number is Negative in Javascript

Recently I was working on one of my projects and I encountered one scenario in which I had to check that whether the number is positive or negative according to the number鈥檚 nature I had to run the logic and then I came to know about Math.sign(). I should share this thing with you 馃槉.. There is a built in fuctinon in javascript Math.sign(), The Math.sign() function returns either a positive or negative +/- 1, indicating the sign of a number passed into the argument....

August 6, 2022 路 1 min 路 Mohammad Shahzaib

Get the Width and Height of an Element using Javascript

In this post we are going to discuss how to get the height and width of an element with Javascript. There are several properties we can look at in order to get the width and height of elements, and it can be tricky to determine which is the right one for your needs. Let鈥檚 discuss about some of these. const containerEle = document.getElementById("container"); const clientWidth = containerEle.clientWidth; const clientHeight = containerEle....

July 30, 2022 路 2 min 路 Mohammad Shahzaib