Javascript Articles

Page 280 of 534

Is there a way to print all methods of an object in JavaScript?

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

In JavaScript, methods are object properties that contain functions. Sometimes you need to inspect an object to discover all its available methods. This tutorial shows how to print all methods of an object using different approaches. A method is simply a function stored as an object property. When you call obj.methodName(), you're executing the function stored in that property. JavaScript provides several ways to discover these function properties. Using Object.getOwnPropertyNames() Method The Object.getOwnPropertyNames() method returns an array of all properties (including non-enumerable ones) found directly on an object. We can filter this array to find only function ...

Read More

Polymer 1.0 dom-repeat should display index starting at 1 with HTML

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

Polymer.js is a JavaScript library created by Google that allows reusing HTML elements for building applications with components. When using dom-repeat in Polymer 1.0, the index starts at 0 by default, but you can display it starting from 1. The Problem By default, dom-repeat provides a zero-based index. If you want to display numbers starting from 1 (like a numbered list), you need to add 1 to the index value. Solution: Using a Helper Function Create a helper function that adds 1 to the index: displayIndex: function(index) { return index ...

Read More

How to set named cookies in JavaScript?

vanithasree
vanithasree
Updated on 15-Mar-2026 651 Views

To set named cookies in JavaScript, use document.cookie with the format name=value. Named cookies allow you to store multiple key-value pairs that can be retrieved later. Basic Syntax document.cookie = "cookieName=cookieValue; expires=date; path=/"; Example: Setting a Customer Name Cookie function WriteCookie() { if (document.myform.customer.value == "") { alert("Enter some ...

Read More

How to design a custom alert box using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 12K+ Views

In this tutorial, we are going to create one custom alert box using JavaScript. The alert box signifies a box that appears with some message on it whenever you click a button and if we add some styling to the box and mould it according to our requirements then it will be a custom alert box. Approach to Design Custom Alert Box To create a custom alert box, we will use a jQuery library which is used to simplify the HTML DOM manipulation and it also provides us with better use of event handling and CSS animation with ...

Read More

How can I pop-up a print dialog box using JavaScript?

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 4K+ Views

To pop-up a print dialog box using JavaScript, use the window.print() method. This method opens the browser's print dialog, allowing users to select printing options like printer choice, page range, and paper size. Syntax window.print(); Basic Example Here's a simple example that opens the print dialog when a button is clicked: Print Dialog Example My Document This content will be printed when you click the print button. ...

Read More

Flexbox layout losing proportions when reduced in size

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 153 Views

Flexbox items can lose their intended proportions when the container shrinks, causing layout distortion. This happens due to default flex shrinking behavior and minimum size calculations. The Problem By default, flex items have flex-shrink: 1 and min-width: auto, which can cause unexpected shrinking behavior when the container becomes smaller than the content. Item 1 with long content Item 2 Item 3 .flex-container { display: flex; width: 300px; border: 1px solid #ccc; } .flex-item { flex: 1; ...

Read More

How to create JavaScript objects using new operator?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 385 Views

The new operator in JavaScript creates instances of objects. It can be used with built-in constructors like Object(), Array(), or with custom constructor functions to create objects with specific properties and methods. Syntax let objectName = new ConstructorFunction(parameters); Using new with Object Constructor The most basic way is using new Object() to create an empty object, then add properties: var dept = new Object(); dept.employee ...

Read More

HTML5 audio control stop button

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 1K+ Views

HTML5 audio elements don't have a built-in stop button, but you can create one by combining the pause() method with resetting the currentTime property. Basic Stop Function To stop audio playback, pause the audio and reset its current time to zero: Stop function stopAudio() { var myPlayer = document.getElementById('myAudio'); myPlayer.pause(); myPlayer.currentTime = 0; } Complete Example with Play/Stop Controls Play Stop var audio = document.getElementById('audioPlayer'); function playAudio() { ...

Read More

How to set multiple cookies in JavaScript?

mkotla
mkotla
Updated on 15-Mar-2026 4K+ Views

In JavaScript, you can set multiple cookies by calling document.cookie multiple times. Each call adds a new cookie to the browser's cookie store. Unlike other properties, document.cookie doesn't overwrite existing cookies — it appends new ones. Basic Syntax for Multiple Cookies document.cookie = "cookie1=value1"; document.cookie = "cookie2=value2"; document.cookie = "cookie3=value3"; Example: Setting Multiple Cookies Here's a complete example showing how to add, list, and remove multiple cookies: var num = 1; ...

Read More

HTML5 meta name = "viewport" doesn't work as expected

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

The HTML5 viewport meta tag controls how web pages are displayed on mobile devices. When it doesn't work as expected, it's often due to incorrect syntax or conflicting properties. Common Issues and Solutions Here are the most effective viewport configurations to fix common display problems: Method 1: Standard Responsive Design For most responsive websites, use this configuration: Responsive Page This page adapts to screen width Content scales properly on all devices. ...

Read More
Showing 2791–2800 of 5,340 articles
« Prev 1 278 279 280 281 282 534 Next »
Advertisements