Found 10483 Articles for Web Development

How can I show a hidden div when a select option is selected in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 12:06:21

17K+ Views

Showing and hiding elements is a common task in JavaScript. It can be used to create dynamic user interfaces, where the content changes depending on the user's input or interaction with the page. One way of doing this is to show a hidden div when a select option is selected. This article will guide you through how to do this using JavaScript. A Boolean attribute is the one that was chosen. It indicates that a choice should be preselected when the page loads if it is present. In the drop-down list, the pre-selected option will be shown first. To ... Read More

Why addEventListener to 'select' element does not work in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 12:02:43

9K+ Views

When a user changes the value of an element, the , , and elements fire the change event. The change event does not always fire for every change to an element's value, unlike the input event. Instead, use querySelector() along with addEventListener(). Let’s discuss one by one to understand how they will work. The addEventListener() Method − The addEventListener() is a method used to register an event handler for the specified event type on the current element. It allows you to specify a function that will be called whenever the specified event occurs on the element. Following ... Read More

How to dynamically create radio buttons using an array in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 12:07:43

5K+ Views

Creating radio buttons dynamically using an array in JavaScript is a useful way to provide users with multiple options for input. When the user clicks on one of the radio buttons, it will be selected and any other choices will be deselected automatically. This process can be automated by looping through an array that contains all the possible values and creating a new radio button element for each item in the array. To dynamically create radio button using an array, use the concept of createElement() and appendChild().Let’s look at the concept to understand more about dynamically creating a radio buttons. ... Read More

WebDriver click() vs JavaScript click().

Debomita Bhattacharjee
Updated on 26-Oct-2020 06:53:23

749 Views

We can click a link with the webdriver click and Javascript click. For the Selenium webdriver click of a link we can use link text and partial link text locator. We can use the methods driver.findElement(By.linkText()) and driver.findElement(By.partialLinkText()) to click.The links in an html code are enclosed in an anchor tag. The link text enclosed within the anchor tag is passed as argument to the driver.findElement(By.linkText()) method. The partial matching link text enclosed within the anchor tag is passed as argument to the driver.findElement(By.partialLinkText()) method. Finally to click on the link the click method is used.Let us see the html ... Read More

Match specific word in regex in JavaScript?

Nikhilesh Aleti
Updated on 22-Sep-2022 12:05:51

11K+ Views

The task is to match a specific word or character which is in regex with a string. The regex (regular expressions) is a pattern that is used to match character combinations in strings. Here we include the test(), match(), and matchAll() methods to match the following word in regex. We have some boundary-type assertions, in which we have used \b. Consider a sentence – “mickey is holding mic.” Using regex - \bmic\b will match the word mic but not the word mic in mickey. It is a word boundary. Another assertion is (g), It is a global search flag. Consider ... Read More

Get price value from span tag and append it inside a div after multiplying with a number in JavaScript?

AmitDiwan
Updated on 24-Oct-2020 12:33:33

1K+ Views

Extract the value and convert it from String to integer to get price value from span tag.ExampleFollowing is the code −            Document           Value=                10                    $(document).ready(function () {       var v = parseInt($(".purchase.amount")       .text()       .trim()       .replace(', ', ''));       var totalValue = v * 10;       console.log(totalValue);   ... Read More

Removing listener from inside outer function in JavaScript?

AmitDiwan
Updated on 24-Oct-2020 12:28:41

92 Views

To remove listener from outer function, use removeEventListener().ExampleFollowing is the code − Document Press Me    var demoId = document.getElementById('demo');    demoId.addEventListener('click', function fun() {       outerFunction(this, fun);    }, false);    function outerFunction(self, funct) {       console.log('outer function is called....');       self.removeEventListener('click', funct, false);       console.log("Listener has been removed...")    } To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.OutputThis will ... Read More

How can I merge properties of two JavaScript objects dynamically?

AmitDiwan
Updated on 24-Oct-2020 12:23:58

242 Views

To merger properties of two objects, you can use the concept of {...object1,...object2,... N).ExampleFollowing is the code −var firstObject = {    firstName: 'John',    lastName: 'Smith' }; var secondObject = {    countryName: 'US' }; var mergeObject = {...firstObject, ...secondObject}; console.log(mergeObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo307.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo307.js { firstName: 'John', lastName: 'Smith', countryName: 'US' }

How to get all combinations of some arrays in JavaScript?

AmitDiwan
Updated on 24-Oct-2020 12:22:27

315 Views

You can use your own function to get all combinations.ExampleFollowing is the code −function combination(values) {    function * combinationRepeat(size, v) {       if (size)          for (var chr of values)       yield * combinationRepeat(size - 1, v + chr);       else yield v;    }    return [...combinationRepeat(values.length, "")]; } var output = combination([4,5]); console.log(output);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo306.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo306.js [ '44', '45', '54', '55' ]

JavaScript/ Typescript object null check?

Nikhilesh Aleti
Updated on 18-Jun-2024 17:36:07

14K+ Views

In this article we will check if an object is a null in Typescript. A variable is undefined until and unless it is not assigned to any value after declaring it. NULL is known as empty or dosen’t exist. In typescript, unassigned values are by default undefined, so in order to make a variable null, we must assign it a null value. To check a variable is null or not in typescript we can use typeof or "===" operator. Using typeofoperator The typeof operator in JavaScript is used to find the datatype of the variable. Example In the example ... Read More

Advertisements