Javascript Articles

Page 525 of 534

How to check if a string has a certain piece of text in JavaScript?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 238 Views

JavaScript provides several methods to check if a string contains a specific piece of text. While the older search() method works, modern approaches like includes() are more intuitive and widely used. Using includes() Method (Recommended) The includes() method returns true if the string contains the specified text, false otherwise. let str = "Tutorialspoint: Free Video Tutorials"; let searchText = "Free Video"; if (str.includes(searchText)) { document.write("Contains"); } else { document.write("Does not contain"); } Contains Using search() Method The search() method returns the ...

Read More

How do I remove a particular element from an array in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 15-Mar-2026 1K+ Views

In JavaScript, removing a particular element from an array refers to the process of deleting or filtering out a specific element so that it no longer exists within that array. Arrays are the most commonly used data structures in JavaScript, allowing developers to store and manipulate collections of items. There are several methods to remove elements from arrays, each with different behaviors and use cases. Method 1: Using splice() Method The splice() method modifies the original array by removing elements at a specified index. Syntax array.splice(index, deleteCount[, element1[, element2[, ...]]]) Parameters ...

Read More

How to redirect to another webpage using JavaScript?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 22K+ Views

The window.location object contains the current location or URL information. We can redirect users to another webpage using the properties of this object. The window prefix is optional and can be omitted. JavaScript provides three main methods to redirect users to another webpage: location.href - Sets or returns the complete URL of the current page location.replace() - Replaces the current document with a new one (no back button history) location.assign() - Loads a new document (keeps back button history) Syntax location.href = "url"; location.replace("url"); ...

Read More

How can I remove all child elements of a DOM node in JavaScript?

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

When building web applications, you often need to clear dynamic content like task lists, shopping carts, or search results. JavaScript provides several methods to remove all child elements from a DOM node efficiently. Here are the main approaches to remove all child elements: Using the removeChild() method with iteration Setting innerHTML to an empty string Using jQuery's empty() method Using the modern replaceChildren() method Using removeChild() Method with Iteration This method iterates through all child nodes and removes them one by one using removeChild(). It's reliable and works across all browsers. Syntax ...

Read More

How to determine if JavaScript object is an event?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In JavaScript, distinguishing between regular objects and event objects is important when handling user interactions and DOM events. An event object contains information about an event that occurred, such as mouse clicks or keyboard presses, while regular objects store data as properties and methods. JavaScript events are actions that happen in the browser, like clicking a button or loading a page. When these events occur, JavaScript creates event objects that contain details about what happened. Let's explore two reliable methods to check if an object is an event. Using the target Property Event objects have a target ...

Read More

How to delete a row from a table using jQuery?

Saleh Alshahrani
Saleh Alshahrani
Updated on 15-Mar-2026 3K+ Views

In this article, we will learn to delete a row from a table using jQuery. jQuery, a fast and lightweight JavaScript library, makes DOM manipulation simple. Deleting a row from a table dynamically is a common requirement in web development, especially when working with forms or data tables. Approach to Delete Rows The approach involves attaching a click event listener to a delete button within the row. When the button is clicked, the corresponding row is removed from the table using jQuery methods. Key jQuery Methods Used The $(document).on('click', 'button.deletebtn', function ...

Read More

How to add a new list element under a \'ul\' using jQuery?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 3K+ Views

In this article, we will learn to add a new list element under a "ul" using jQuery. jQuery is a popular JavaScript library that simplifies HTML manipulation, event handling, and animations. One of its practical applications is dynamically adding elements to a webpage without requiring a full page reload. Why Use jQuery? DOM (Document Object Model) updating using basic JavaScript might become difficult and needs more than one line of code. jQuery has simplified it through easy selectors and functions. Employing jQuery helps us: Select elements efficiently Handle ...

Read More

What is the difference between jQuery and JavaScript?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 15-Mar-2026 2K+ Views

Both JavaScript and jQuery serve the same overarching objective of making webpages more interactive and dynamic. They give websites a sense of vibrancy. People may ask why there is a need for two distinct concepts if they serve the same function. Read through this article to find out how jQuery differs from JavaScript. What is JavaScript? JavaScript is a lightweight programming language that is used most often as a component of webpages. Its webpage implementations enable client-side script to interact with the user and create dynamic sites. It is a programming language that is interpreted and can handle ...

Read More

How to handle bind an event using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 11K+ Views

In this tutorial, we will learn how to bind events using JavaScript. Events are actions or occurrences triggered by the browser or users. There are various types of events that represent different activities. For example, if a user clicks on a button, it triggers a "click" event. Similarly, when a webpage finishes loading, it triggers a "load" event. An Event Listener is a program that continuously listens for events to occur. Event Handlers are functions that execute when an event occurs. JavaScript binds events to their respective event handlers using the addEventListener method. Binding Events with addEventListener ...

Read More

JavaScript variables declare outside or inside loop?

Abdul Rawoof
Abdul Rawoof
Updated on 15-Mar-2026 5K+ Views

In JavaScript, variables can be declared either inside or outside loops without performance differences. However, the choice affects variable scope and code readability. Variable Scope: var vs let With var, variables are function-scoped regardless of where declared. With let, variables are block-scoped, meaning they're only accessible within their block. Example: Variable Declared Outside Loop When declared outside, variables have broader scope and can be accessed throughout the function: function myFunction1() { var i; // Function scope - can be used throughout the function ...

Read More
Showing 5241–5250 of 5,340 articles
« Prev 1 523 524 525 526 527 534 Next »
Advertisements