Found 6685 Articles for Javascript

Access an Element in Type Script

Shubham Vora
Updated on 21-Feb-2023 15:33:50

11K+ Views

In TypeScript, to access an element, or we can say HTML components, we use the Document Object Model (DOM). The DOM defines an HTML and XML programming interface that visualizes a document's structure as a tree of nodes. A paragraph, a button, a div, a heading, etc., are just a few examples of the document elements each node in the tree represents. The document object in TypeScript serves as the doorway to the DOM. This means we can easily access the elements of the DOM using TypeScript. There are several ways to access elements, those are − Using the ... Read More

How to change the value of a global variable inside of a function using JavaScript?

Abhishek
Updated on 17-Feb-2023 11:44:02

4K+ Views

There are two types of variables can be declared in any programming languages in context of their accessing scope. The Local variable and the Global variable. Global Scoped Variables − The global scoped variables are the variables which are declared globally inside the code file and can be accessed by any code block or any function inside the file. The scope of these variables is global. Local Scoped Variables − These are the variable, which declared inside a function or a particular block of code and can only be accessed or used within that particular block of code not outside ... Read More

How to Change the Time Interval of setinterval() Method at RunTime using JavaScript ?

Abhishek
Updated on 17-Feb-2023 11:57:00

2K+ Views

The setInterval() method is used to call a particular block of code again and again after a particular interval of time that is given to it in its round braces as parameter. The setInterval() method accepts two parameters, the first is the code that has to be executed again and again while the second is the time in which the code has to be execute again. In this article, we are going to learn about the methods of changing the time interval of the setInterval() method at the runtime. So that, it will execute the given code at the irregular ... Read More

How to change the text of a label using JavaScript?

Abhishek
Updated on 17-Feb-2023 11:55:49

5K+ Views

Before going to learn about the method of changing the text of a label element in HTML document, let us understand what is the label tag itself? The label tag helps in improving the usability of the web page for mouse users, as it can toggle the text inside it if the user clicks on it. Let us now discuss about the methods of changing the text of the label element using JavaScript. JavaScript allow us to use two inbuilt properties to change the text of any element in the HTML document, as listed below − Using the innerHTML ... Read More

How to change the text and image by just clicking a button in JavaScript?

Abhishek
Updated on 17-Feb-2023 11:54:44

19K+ Views

The text given to an particular element and the image given in an img element can be easily changed using the JavaScript. We can use the onclick event with the button element in the HTML document to make this happen when the button is clicked. To change the text on click to the button we assign a function to the onclick event as the value which performs the required changes. Let us understand the methods of changing the text and the image individually using JavaScript in details with the help of code examples. Changing text of an element JavaScript provide ... Read More

How to change the src attribute of an img element in JavaScript / jQuery?

Abhishek
Updated on 17-Feb-2023 11:53:22

14K+ Views

There are different methods to change the path of an image given to the src attribute of an img element in HTML document using the JavaScript as well as jQuery. Method of changing the src attribute of an img element using JavaScript − Use the src property in JavaScript. Methods of changing the src attribute of an img element using jQuery − Using attr() method Using prop() method Let us discuss each of the above listed methods of changing the src of an img element one by one in details − Using src property in JavaScript ... Read More

How to change the shape of a textarea using JavaScript?

Abhishek
Updated on 17-Feb-2023 11:51:52

305 Views

Textarea is a type of box with dynamic width and height, that means when the text is entered inside it, the text will not overflow and will only be contained by this texarea as it can dynamically increase or decrease its height and width. The textarea is mainly used inside the forms to get the full address of user and some other content with a larger text content. Commonly, A textarea is in the form of square shape or the rectangular shape, which can be changes using JavaScript as well as CSS. In this article, we are going to learn ... Read More

How to change the ID of the element using JavaScript?

Abhishek
Updated on 17-Feb-2023 11:49:19

3K+ Views

Generally, the ID given to any element in an HTML document is unique and can be assign to an element only once. But it is possible to change that id later using the JavaScript following the same rule of uniqueness for new ID as well as only single element can contain the new ID. In this article, we are going to learn about the ways of changing the ID of an element using JavaScript. JavaScript provides us or allow us to use the id property to get the id of any element as well as to change or add a ... Read More

How to debug JavaScript Program?

Abhishek
Updated on 17-Feb-2023 11:47:30

186 Views

While programming in any programming language, it is very general to do the mistakes in the logic building or in following the syntax rules of a language, which results in formation of errors and failure of our code to perform every task as expected. In this article, we are going to learn, how we can find the exact location of those errors and how we can fix them to make our code work as expected. The process of finding the errors in the code and then fixing them is known as Debugging. There are different ways of debugging a JavaScript ... Read More

How to calculate minutes between two dates in JavaScript?

AmitDiwan
Updated on 16-Feb-2023 15:31:26

10K+ Views

In this article, you will understand how to calculate minutes between two dates in JavaScript. The Date object works with dates and times. Date objects are created with new Date(). JavaScript will use the browser's time zone and display a date as a full text string. Example 1 In this example, we use a function to find the time difference. function minutesDiff(dateTimeValue2, dateTimeValue1) { var differenceValue =(dateTimeValue2.getTime() - dateTimeValue1.getTime()) / 1000; differenceValue /= 60; return Math.abs(Math.round(differenceValue)); } dateTimeValue1 = new Date(2020, 12, 12); console.log("The first date time value is defined ... Read More

Advertisements