Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 280 of 534
Is there a way to print all methods of an object in JavaScript?
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 MorePolymer 1.0 dom-repeat should display index starting at 1 with HTML
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 MoreHow to set named cookies in JavaScript?
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 MoreHow to design a custom alert box using JavaScript?
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 MoreHow can I pop-up a print dialog box using JavaScript?
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 MoreFlexbox layout losing proportions when reduced in size
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 MoreHow to create JavaScript objects using new operator?
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 MoreHTML5 audio control stop button
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 MoreHow to set multiple cookies in JavaScript?
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 MoreHTML5 meta name = "viewport" doesn't work as expected
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