Javascript Articles

Page 303 of 534

How to remove two parts of a string with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 3K+ Views

This tutorial teaches us how to remove the text part between two parts of a string with JavaScript. We are given two ends that can be a string or a character and we need to remove the string lying in between them. We will use regular expressions with JavaScript's replace() method to accomplish this task. Syntax Here's the basic syntax for removing part of a string between two characters or sub-strings: var str = "your string here"; var final_str = str.replace(/(first_part).*?(second_part)/, '$1$2'); In the above syntax: first_part - The starting delimiter (string ...

Read More

How to set the CSS margin properties in one declaration?

George John
George John
Updated on 15-Mar-2026 351 Views

The margin property defines the space around an HTML element. It is possible to use negative values to overlap content. It specifies a shorthand property for setting the margin properties in one declaration. Syntax margin: value; margin: top right bottom left; margin: top horizontal bottom; margin: vertical horizontal; Margin Value Patterns The margin property accepts 1 to 4 values with different behaviors: Values Result Example 1 value All sides same margin: 20px 2 values vertical | horizontal margin: 10px 5px 3 values top | horizontal ...

Read More

How to catch all JavaScript errors?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 12K+ Views

To catch all JavaScript errors, we can use the window.onerror method which acts like a global try-catch statement. The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page. The onerror event handler provides three pieces of information to identify the exact nature of the error: Error message − The same message that the browser would display for the given error URL − The file in which the error occurred ...

Read More

How to catch syntax errors in JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn how to catch syntax errors in JavaScript and handle them effectively. JavaScript throws various types of errors when we write incorrect code: ReferenceError when calling undefined variables, TypeError when trying to modify immutable values inappropriately, and SyntaxError when the code structure is invalid. What is Syntax Error? A SyntaxError occurs when JavaScript encounters code that violates the language's syntax rules. Unlike runtime errors, syntax errors are detected during the parsing phase, before the code executes. Common Causes of Syntax Errors Missing brackets: Unclosed parentheses (), braces ...

Read More

How can I get a JavaScript stack trace when I throw an exception?

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

This tutorial teaches us to get a JavaScript stack trace when we throw an exception. Usually, the developer uses the stack trace to identify the errors while executing the program's code. However, we use the stack trace to debug the program. Using the stack trace, we can get knowledge of any kind of exceptions, such as constructor error, naming error, etc., in our program, and we can correct them. Before we approach analyzing the error using the stack trace, we should know how to stack trace works. How does the call stack trace work? The stack ...

Read More

How to skip character in capture group in JavaScript Regexp?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 1K+ Views

You cannot skip a character in a capture group. A match is always consecutive, even when it contains things like zero-width assertions. However, you can use techniques to extract specific parts while ignoring unwanted characters. Understanding the Problem When you need to match a pattern but only capture certain parts, you can use non-capturing groups (?:...) and capturing groups (...) strategically to ignore unwanted characters. Example: Extracting Username After Prefix The following example shows how to match a string with a prefix but only capture the username part: ...

Read More

Set Outset border with CSS

Samual Sam
Samual Sam
Updated on 15-Mar-2026 541 Views

To set an outset border with CSS, use the border-style property with the value outset. An outset border creates a 3D effect that makes the element appear raised or protruding from the page. Syntax border-style: outset; /* Or combine with width and color */ border: width outset color; Example Outset Border Example This paragraph has no border. ...

Read More

How do you access the matched groups in a JavaScript regular expression?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 972 Views

This tutorial will teach us to access the matched groups in JavaScript regular expression. The regular expression is the sequence of the character, also called the RegEx, and it is useful to match specific patterns in the string. There can be more than one match for the specific pattern in the string. To get the occurrence of all matches, we have explained the different methods below in this tutorial. We will also see the various usage of the regular expression in this article. Use the 'g' flag while creating the Regex When we add 'g' as ...

Read More

How to set current time to some other time in JavaScript?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 622 Views

You cannot directly modify the system time with JavaScript since it uses the system's clock through the Date object. However, you can simulate different times by adjusting timezones or creating custom date objects with specific values. Method 1: Using Timezone Conversion You can display time for different timezones by calculating the offset from UTC: var date, utc, offset, singaporeTime; date = new Date(); ...

Read More

Change the width of the bottom border with CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 240 Views

The border-bottom-width CSS property controls the thickness of an element's bottom border. This property only works when a border style is defined, as borders are invisible by default. Syntax border-bottom-width: value; Common values include thin, medium, thick, or specific measurements like 1px, 5px, 0.5em. Example This is demo content with a 6px bottom border. ...

Read More
Showing 3021–3030 of 5,340 articles
« Prev 1 301 302 303 304 305 534 Next »
Advertisements