Articles on Trending Technologies

Technical articles with clear explanations and examples

Get value of any attribute from XML data in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

To get the value of any attribute from XML data in JavaScript, you can use jQuery's attr() method or native JavaScript methods like getAttribute(). This is useful when working with XML strings or DOM elements that contain XML data. Using jQuery's attr() Method The attr() method allows you to extract attribute values from XML elements wrapped in jQuery objects: XML Attribute Example ...

Read More

Trigger a button click and generate alert on form submission in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 11K+ Views

In JavaScript, you can trigger a button click event and generate an alert on form submission using event handlers. This tutorial demonstrates how to attach a click event listener to a button and display an alert when the form is submitted. HTML Structure First, let's create a basic HTML form with a button: Submit JavaScript Event Handler Using jQuery, you can attach a click event handler to the button based on its ID: $("#submitForm").click(function() { alert("The Form has been Submitted."); }); Complete Example Here's ...

Read More

Converting days into years months and weeks - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

We are required to write a JavaScript function that takes in a number (representing the number of days) and returns an object with four properties: years, months, weeks, days The properties should have proper values that can be made from the total number of days. We assume a standard year has 365 days and each month has 30 days for simplicity. Problem Example If the input is 738 days, the output should be: { years: 2, months: 0, weeks: 1, days: 1 } ...

Read More

How to initialize a boolean array in JavaScript?

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

In JavaScript, boolean arrays are useful for storing true/false values. You can initialize them using several methods, each with different advantages depending on your needs. We can initialize a boolean array in JavaScript in three ways: Using the fill() Method Using the Array.from() Method Using the for Loop Using the fill() Method The fill() method is the simplest way to create a boolean array with all elements having the same value. It fills all array positions with a static value from start to end. ...

Read More

How to set the width of the top border with JavaScript?

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

In this tutorial, we will learn how to set the width of the top border with JavaScript. The border of an element is the outer part of the element. The border width for each side can be set with different JavaScript properties. For example, to set the width of the top border in JavaScript, use the borderTopWidth property. There are two approaches to specifying the width of the top border − Using the setProperty method Using the borderTopWidth property Using the setProperty Method In JavaScript, any property ...

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

Indent the text of a paragraph with CSS

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

The text-indent property is used to indent the first line of text in a paragraph or block-level element. This creates a traditional paragraph indentation effect commonly seen in books and formal documents. Syntax text-indent: value; Possible Values Length units: px, em, rem, cm, mm, in, pt Percentage: % (relative to parent element's width) Keywords: inherit, initial, unset Example: Basic Text Indentation Here's how to implement text indentation using different measurement units: ...

Read More

What is the importance of "enumerable" attribute in defining a property in JavaScript object?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 397 Views

The enumerable attribute controls whether a property appears in object enumeration methods like for...in loops, Object.keys(), and JSON.stringify(). When using Object.defineProperty(), properties are non-enumerable by default. Syntax Object.defineProperty(objectName, propertyName, { value: propertyValue, enumerable: true/false }) Default Behavior: Non-enumerable Property When enumerable is not specified, it defaults to false, making the property invisible to enumeration methods: var object = {one: 1}; Object.defineProperty( object, ...

Read More

Can we check if a property is in an object with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 160 Views

JavaScript provides multiple ways to check if a property exists in an object. The most common approaches are using the in operator, hasOwnProperty() method, and Object.hasOwn() method. Using hasOwnProperty() Method The hasOwnProperty() method checks if the object has a specific property as its own (not inherited from the prototype chain). Property Check body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } ...

Read More

Reverse all the words of sentence JavaScript

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

We are required to write a JavaScript function that takes in a string and returns a new string which has all the words reversed from the original string. For example − If the original string is − "Hello World how is it outside" Then the output should be − "olleH dlroW woh si ti edistuo" Now, let's write the code for this function − Example const str = 'Hello World how is it outside'; const reverseSentence = str => { const arr = ...

Read More
Showing 18911–18920 of 61,297 articles
Advertisements