Found 10483 Articles for Web Development

HTML DOM Storage setItem() method

AmitDiwan
Updated on 19-Feb-2021 05:16:28

134 Views

The HTML DOM Storage setItem() method is used for removing a storage object item by passing a given key name.SyntaxFollowing is the syntax for Storage removeItem() method −localStorage.removeItem(keyname, value);ORsessionStorage.removeItem(keyname, value );Here, keyname is of type string and represents the key name used for getting the value. The second parameter value represents the new value that will replace the old value.ExampleLet us look at the example for the Storage setItem() method −Live Demo Storage setItem() method example Create the localstorage item by clicking the below button CREATE Display the localstorage item by clicking the below button DISPLAY ... Read More

HTML DOM Storage removeItem() method

AmitDiwan
Updated on 20-Aug-2019 06:05:15

143 Views

The HTML DOM Storage removeItem() method is used for removing a storage object item by passing a given key name.SyntaxFollowing is the syntax for Storage removeItem() method −localStorage.removeItem(keyname);ORsessionStorage.removeItem(keyname);Here, keyname is of type string and represents the name of the item to be removed.ExampleLet us look at the example for the Storage removeItem() method − Storage removeItem() method example Delete the localstorage item by clicking the below button DISPLAY    localStorage.setItem("TEXT1", "HELLO WORLD");    function itemDelete() {       localStorage.removeItem("TEXT1");       itemShow();    }    function itemShow() {       var x = ... Read More

HTML DOM Storage length property

AmitDiwan
Updated on 19-Feb-2021 05:18:43

169 Views

The HTML DOM Storage length property is used for getting the number of items that are present inside the browser’s storage object. The storage object can be a localStorage object or a sessionStorage object.SyntaxFollowing is the syntax for −Storage length property using localStorage object −localStorage.length;Storage length property using sessionStorage objectsessionStorage.length;ExampleLet us look at the example for the Storage length property −Live Demo Storage length property example Get how many storage items are stored in the local storage object by clicking the below button GET NUMBER    function itemNum() {       var num = localStorage.length; ... Read More

HTML DOM Storage key() method

AmitDiwan
Updated on 20-Aug-2019 05:59:38

146 Views

The HTML DOM Storage key() method is used for returning the key name at a given index in a storage object. The index is passed as a parameter to key() method. The storage object can be a session object or localStorage object.SyntaxFollowing is the syntax for −Storage key() method using localStorage −localStorage.key(index);Storage key() method using sessionStorage −sessionStorage.key(index);Here, index is of type integer representing the key number that you want to get the name for.ExampleLet us look at the example for the Storage key() method − storage key() method example Get the first object key name by clicking on ... Read More

HTML DOM Storage getItem() method

AmitDiwan
Updated on 19-Feb-2021 05:21:20

132 Views

The HTML DOM Storage getItem() method is used for obtaining a storage object by passing a given key name. It will return the key’s values and if there is no key with that given name then NULL will be returned.SyntaxFollowing is the syntax for Storage getItem() method −localStorage.getItem(keyname);ORsessionStorage.getItem(keyname);Here, keyname is of type string and represents the name of the item to be obtained.ExampleLet us look at an example for the HTML DOM Storage getItem() method −Live Demo Storage getItem() method example Create a localStorage item with the name CLICKS to count the number of clicks on the create ... Read More

HTML DOM Storage Event

AmitDiwan
Updated on 20-Aug-2019 05:52:26

200 Views

The HTML DOM storage event triggers when there has been a change in the storage area of the window. The storage event is triggered only if the other window makes the storage area change for a window. This event doesn’t bubble and is cancellable too.SyntaxFollowing is the syntax for −window.addEventListener("storage", SCRIPT);ExampleLet us look at an example for the Storage Event − Storage Event Example Create the visit localStorage item by clicking the below button CREATE    var y=1;    window.addEventListener("storage", DisplayChange);    function DisplayEvent(event) {       document.getElementById("Sample").innerHTML = "The number of visits has been ... Read More

How "getElementByID" works in JavaScript?

Lokesh Yadav
Updated on 12-Nov-2024 17:48:07

7K+ Views

This article discusses about how “getElementByID” method work in JavaScript. The getElementByID() method in JavaScript is a document method. When we give a specific string which should match the ID of the HTML element, it returns the element object. Every HTML element can be assigned a unique ID. If two or more elements have the same ID, then the getElementByID() method returns the first element. The getElementByID() method is used for the faster access of an element. It helps us to manipulate an HTML element within our document and is supported by all the modern browsers. If the element is ... Read More

HTML DOM stopPropagation() Event method

AmitDiwan
Updated on 19-Feb-2021 05:24:19

1K+ Views

The HTML DOM stopPropagation() event method is used for stopping the propagation of the given element. This means that clicking on the parent element won’t propagate to children and clicking on the children elements won’t propagate to parent using the stopPropagtion() method. The event propagation is also called event bubbling.SyntaxFollowing is the syntax for the stopPropagation() event method −event.stopPropagation()ExampleLet us look at the example for the stopPropagation() event method −Live Demo    #DIV_1 {       background: lightpink;       width:130px;       height:130px;       margin-left:40%;       text-align:center;    } ... Read More

Shift() vs pop() methods in JavaScript?

Manisha Patil
Updated on 23-Aug-2022 13:25:47

2K+ Views

To remove an element from an array with JavaScript, use the shift() and pop() functions. However, there is a slight distinction among them. While pop() removes the last element from an array, shift() removes the first element from an array. When using the shift() method, the value that was deleted is returned after the element at the zeroth position is removed and values at subsequent indexes are shifted downward. The return value is undefined if the length property is 0. A function that modifies data is shift(). Both the substance and the length of this are altered. Use arr.slice(1) instead ... Read More

HTML DOM Span object

AmitDiwan
Updated on 19-Feb-2021 05:27:35

2K+ Views

The HTML DOM span object is associated with the HTML element. We can create and access span element using the createElement() and getElementById() method respectively.SyntaxFollowing is the syntax for −Creating a span object −var a = document.createElement("SPAN");ExampleLet us look at an example for the span object −Live Demo Span object example Create a span element by clicking the below button CREATE This is some text inside a p element    function createSpan() {       var s = document.createElement("SPAN");       var txt = document.createTextNode("This is some text inside the span element");     ... Read More

Advertisements