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
Articles by Abhishek Kumar
14 articles
How to show the number of links in a document with JavaScript?
We use the links property of the document object to show the number of links in a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It contains all the information about the condition of the browser as well as the web page. The links is a property of the document object that returns a list of all the hyperlinks present in the HTML document. A hyperlink may look something like this: "https://www.tutorialspoint.com/php" The links property of the document object lists all HTML ...
Read MoreHow to show name/value pairs of cookies in a document with JavaScript?
We use the cookie property of the document object to show the name/value pairs of cookies in a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It contains all the information about the condition of the browser as well as the web page. A server serves requests when a connection is set up and forgets everything about the user as soon as the connection is closed. This posed a nasty problem of bad user experience to the community. A cookie resolves this problem by storing small ...
Read MoreHow to show the full URL of a document with JavaScript?
We use the URL property of the document object to show the full URL of a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It contains all the information about the condition of the browser as well as the web page. URL stands for Uniform Resource Locator. It contains the address of a resource on the internet. A typical URL looks something like this: http://www.example.com/index.html The Document Object Model of JavaScript acts as a layer of abstraction on the HTML page, creating ...
Read MoreHow to show the index of the selected option in a dropdown list with JavaScript?
In JavaScript, we use the selectedIndex property to get the index of the selected option in a dropdown list. This property returns a zero-based index value that indicates which option is currently selected. Dropdown lists are an essential part of user interfaces, allowing users to select one or multiple options from a predefined list. Understanding how to retrieve the selected option's index is crucial for form handling and user interaction. Using the selectedIndex Property The selectedIndex property is part of the DOM and contains the index of the currently selected option in a dropdown list. The indexing ...
Read MoreHow to create many Javascript variables in a single statement?
We can create many JavaScript variables in a single statement using the var, let, and const keywords. Instead of declaring every variable individually, we can chain many variables together with commas (, ) in a single statement. Since JavaScript is a loosely typed language, variables of different data types can be declared in the same sentence as well. Syntax var variable1 = value1, variable2 = value2, variable3 = value3; let variable1 = value1, variable2 = value2, variable3 = value3; const variable1 = value1, variable2 = value2, variable3 = value3; Using var Keyword The var ...
Read MoreHow to use an HTML button to call a JavaScript function?
We use the onclick event attribute property of the HTML button to call a JavaScript function. The JavaScript code provided in the onclick attribute executes when the button is clicked. There are various attributes provided with the button tag in HTML that allows us to customize the button's functionality and also let us decide how and what the button triggers. Using the onclick Event in JavaScript The onclick event of the button element expects JavaScript code that is triggered when the button is clicked upon. So we put the function that needs to be called in the onclick ...
Read MoreHow to use JavaScript to set cookies for a specific page only?
We can set cookies for a specific page only using JavaScript. We use the path attribute of the document.cookie property to set the cookie on a specific webpage. Cookies are small text files (4 KB) that store important information such as username, email, session id, and other preferences that help customize the webpage for a particular user. The pathname property of the Window location returns a string containing the path of the current webpage. The path is basic information about where the current webpage is stored on the server. document.cookie Syntax The document.cookie property returns a list ...
Read MoreHow to show hyperlinks in JavaScript alert?
JavaScript's native alert() function only displays plain text and doesn't support clickable hyperlinks. To show hyperlinks in alert-style dialogs, we use the jQuery UI dialog API, which creates customizable modal windows that can contain HTML elements including clickable links. The standard JavaScript alert box is intentionally limited to text-only content for security reasons. However, jQuery UI provides a flexible alternative that allows rich content while maintaining the alert-like behavior users expect. Limitations of JavaScript alert() The native window.alert() method only accepts string parameters and renders them as plain text. Any HTML tags are displayed literally rather than ...
Read MoreHow to use JavaScript to show a confirm message?
In this tutorial, we will learn how to use JavaScript to show a confirm message. We use window.confirm() method of JavaScript to show a confirm message. A confirm message is enclosed in a confirm dialog box which is a modal window. Such a window takes focus upon being created and doesn't go out of focus until the user responds to it. Confirmation Dialog Box in JavaScript A confirm message is a yes/no message for the user that requires immediate attention. A confirmation dialog box usually gets triggered in response to some action requested by the user. This action ...
Read MoreHow to use for...in statement to loop through an Array in JavaScript?
The for...in statement in JavaScript iterates over all enumerable properties of an object or array. While it can be used with arrays, it's primarily designed for objects since it iterates over property names (indices for arrays) rather than values. Syntax for (variable in object) { // code block to be executed } The loop variable receives the property names (or array indices), not the actual values. Using for...in with Arrays Here's how for...in works with arrays: for...in loop with Arrays ...
Read More