Anvi Jain

Anvi Jain

427 Articles Published

Articles by Anvi Jain

Page 3 of 43

How to format JavaScript date into yyyy-mm-dd format?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 4K+ Views

To format a JavaScript date into "yyyy-mm-dd" format, you can use several methods. The most common approaches are using toISOString() with substring extraction or building the format manually. Using toISOString() Method The toISOString() method returns a date in ISO 8601 format. To get just the "yyyy-mm-dd" part, extract the first 10 characters: JavaScript Date Formatting var date = new Date(); var formattedDate = date.toISOString().substring(0, 10); ...

Read More

Creating content with HTML5 Canvas much more complicated than authoring with Flash

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 197 Views

Flash provided amazing GUI tools and visual features for animations, allowing developers to build multimedia content within a self-contained platform. However, Flash required browser plugins and had security concerns that led to its deprecation. HTML5's element offers a modern, plugin-free alternative for creating graphics and animations using JavaScript. It provides direct access to a drawing context where you can render shapes, images, and complex animations programmatically. Basic Canvas Setup A canvas element requires only width and height attributes, plus standard HTML attributes: Drawing with Canvas Unlike Flash's visual timeline, Canvas ...

Read More

How objects are organized in a web document? How is it arranged in a hierarchy?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 293 Views

The objects in a web document are organized in a hierarchical structure called the Document Object Model (DOM). This hierarchy represents the relationship between different elements and allows JavaScript to interact with web page components systematically. DOM Hierarchy Structure The DOM follows a tree-like structure where each object has a specific position and relationship with other objects: Window object − Top of the hierarchy. It represents the browser window and is the global object for all JavaScript operations. ...

Read More

With JavaScript RegExp find a character except newline?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 299 Views

To find a character except for a newline, use the dot metacharacter . (period). The dot matches any single character except the newline character (). Syntax /./ // Matches any character except newline /.+/ // Matches one or more characters except newline /a.b/ // Matches 'a', any character, then 'b' Example JavaScript Regular Expression ...

Read More

How to create domain-based cookies using JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 417 Views

To create a domain-based cookie, set the domain and path attribute on your cookie. Domain-based cookies are accessible across all subdomains of the specified domain. Syntax document.cookie = "cookieName=value; domain=.example.com; path=/"; Domain Cookie Format domain=.example.com The dot prefix (.) makes the cookie available to all subdomains like www.example.com, api.example.com, etc. Example: Setting Domain-Based Cookie function WriteCookie() { if( document.myform.customer.value == "" ...

Read More

How to set the left padding of an element with JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 763 Views

Use the paddingLeft property in JavaScript to set the left padding of an element. This property allows you to dynamically modify the spacing between an element's content and its left border. Syntax element.style.paddingLeft = "value"; The value can be specified in pixels (px), percentages (%), em units, or other CSS length units. Example #box { border: 2px solid ...

Read More

How to create a dialog with "yes" and "no" options in JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 3K+ Views

JavaScript's built-in confirm() dialog only provides "OK" and "Cancel" buttons. To create a custom dialog with "Yes" and "No" options, you need to build a custom modal using HTML, CSS, and JavaScript. Built-in confirm() Limitation The standard confirm() function cannot be customized to show "Yes/No" buttons: // Built-in confirm() only shows OK/Cancel let result = confirm("Do you want to continue?"); console.log(result ? "User clicked OK" : "User clicked Cancel"); Custom Yes/No Dialog Solution Here's a complete custom dialog implementation using jQuery: ...

Read More

What is Addition Operator (+) in JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 343 Views

The addition operator (+) in JavaScript is used to add two numeric operands together. It performs mathematical addition and returns the sum of the values. Syntax result = operand1 + operand2; Example You can try to run the following code to work with the addition operator: var a = 33; var b = 10; ...

Read More

How to redirect website after certain amount of time without JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 6K+ Views

To redirect from an HTML page without JavaScript, use the META tag with the http-equiv="refresh" attribute. This provides an HTTP header that tells the browser to automatically redirect after a specified number of seconds. Through this method, you can automatically redirect your visitors to a new homepage or any other page. Set the content attribute to 0 if you want the redirect to happen immediately. Syntax Parameters The content attribute contains two parts separated by a semicolon: seconds - Number of seconds to wait before redirecting url - The destination ...

Read More

How do I split a string, breaking at a particular character in JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 279 Views

JavaScript's split() method breaks a string into an array at every occurrence of a specified character or substring. This is useful for parsing data, processing text, or formatting output. Syntax string.split(separator, limit) Parameters separator: The character or string to split on limit: (Optional) Maximum number of splits to make Basic Example Let's split a string at every tilde (~) character: String Split Example ...

Read More
Showing 21–30 of 427 articles
« Prev 1 2 3 4 5 43 Next »
Advertisements