Articles on Trending Technologies

Technical articles with clear explanations and examples

How to find the id of the form a button belongs to in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 5K+ Views

In this tutorial, we will learn how we can find the id of the form element to which a button belongs using JavaScript. In HTML, we can use button tag in two ways with form tag, where it can be used to perform some activity in the form when it is clicked, as listed below − Button is inside the FORM tag Button is outside the FORM tag No matter where the button is located, whether it is inside or outside, we can find the ID of the form tag ...

Read More

How to create JavaScript regexes using string variables?

Abhinaya
Abhinaya
Updated on 15-Mar-2026 208 Views

Yes, use new RegExp(pattern, flags) to create JavaScript regular expressions from string variables. This is essential when you need to build patterns dynamically or when the pattern comes from user input or variables. Syntax new RegExp(pattern, flags) Parameters pattern: A string containing the regular expression pattern flags: Optional string specifying flags like 'i' (case-insensitive), 'g' (global), 'm' (multiline) Basic Example var str = 'HelloWorld'.replace(new RegExp('hello', 'i'), ''); document.write(str); ...

Read More

Wrap Strings of Text in Bootstrap Navbar

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 654 Views

To wrap strings of text in a Bootstrap navbar, use the .navbar-text class. This class ensures proper vertical alignment and styling for non-link text content within navigation bars. What is navbar-text? The .navbar-text class is specifically designed for adding non-interactive text elements to Bootstrap navbars. It provides appropriate spacing, alignment, and color styling that matches the navbar's design. Example You can try to run the following code to set text in Bootstrap Navbar: Bootstrap Navbar Text Example ...

Read More

Write the syntax of javascript with a code to demonstrate it?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 278 Views

JavaScript Tags JavaScript code must be placed within HTML tags to execute properly. These script tags can be positioned in different locations within an HTML document. Where to Place JavaScript JavaScript can be embedded in three main locations: Head section: Scripts in the tag load before the page content Body section: Scripts in the tag execute as the page loads External file: Scripts can be linked from separate .js files Basic JavaScript Syntax JavaScript syntax includes variables, functions, and DOM ...

Read More

How to make your code faster using JavaScript Sets?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

While writing code, we always try to make our code easier to read, less complex, more efficient, and smaller in size. For that, we follow several methodologies which make our code efficient. In this article, we shall focus on some techniques based on JavaScript Sets to perform certain array-like or collection-based applications which will run faster and the code will also be concise. How Sets Differ from Arrays Arrays are indexed collections where each element is associated with a specific index. On the other hand, Sets are keyed collections where data elements are ordered based on their key ...

Read More

Converting a string to a date in JavaScript

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 4K+ Views

In this article, we are going to discuss how to convert a string value to a Date object in JavaScript. There are two ways to achieve this − Using the constructor of the Date class − This constructor accepts a string value representing the date value, converts it into a Date object, and returns the result. Using the Date.parse() method − Same as the Date constructor this method accepts a string value parses and returns the date value in the form of milliseconds. Let us see these solutions with examples − Using the Date() constructor ...

Read More

JavaScript unescape() with example

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 310 Views

The JavaScript unescape() function is used to decode strings that were encoded with the escape() function. This function is deprecated since JavaScript 1.5 and should not be used in modern code. Use decodeURIComponent() instead. Syntax unescape(encodedString) Parameter: encodedString - The string to be decoded. Return Value: A new decoded string. Example with unescape() (Deprecated) JavaScript unescape() Example body { ...

Read More

Binding an object's method to a click handler in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 295 Views

Binding an object's method to a click handler is essential when you need to maintain the correct this context within the method. This ensures the method can access the object's properties and other methods properly. Understanding the Context Problem When directly assigning an object method to an event handler, the this context gets lost and refers to the event target instead of the original object. Example Binding Object Methods to Click Handlers ...

Read More

Getting elements of an array depending on corresponding values of another JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 655 Views

Suppose we have two arrays, for example consider the following two: const array1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; const array2 = [ 1, 0, 0, 1 , 0, 0, 1, 0]; Both arrays are bound to have the same length. We need to write a function that, when provided with an element from the second array, returns a subarray from the first array containing all elements whose index corresponds to the index of the element we took as an argument in the second array. For example: findSubArray(0) should return: ...

Read More

addEventListener() not working more than once with a button in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

The addEventListener() method works multiple times by design. If it seems to work only once, the issue is usually in your event handler function or how you're setting up the listener. Common Problem: Removing the Element A frequent mistake is removing or replacing the button element inside the event handler, which destroys the event listener: addEventListener Problem Bad Example - Works Once ...

Read More
Showing 17241–17250 of 61,297 articles
Advertisements