Found 8591 Articles for Front End Technology

JavaScript: lexical scoping issue using new keyword constructor while adding inner function?

AmitDiwan
Updated on 03-Oct-2020 13:46:06

130 Views

To fix this, use the concept of this keyword. User another variable to hold the value of object, to use that inside the inner function.ExampleFollowing is the code −function Employee() {    this.technologyName = "JavaScript";    var currentTechnologyName = this;    function workingTechnology() {       console.log("I am working with " + currentTechnologyName.technologyName + " Technology");    }    workingTechnology(); } var currentTechnology = new Employee();To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo216.js.The output is as follows −PS C:\Users\Amit\JavaScript-code> node demo216.js I am working with JavaScript Technology

How do I console.log JavaScript variables as it relates to DOM?

AmitDiwan
Updated on 03-Oct-2020 13:41:56

129 Views

To display variables on console, use document.getElementById(“”).ExampleFollowing is the code − Live Demo            Document        const data = document.getElementById("printTheData");    console.log(data); To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −Output in the console −

How to change my code to uncheck radio button from JavaScript to jQuery?

AmitDiwan
Updated on 03-Oct-2020 13:38:21

530 Views

Let’s say the following are our radio buttons, which we have set checked −Gender Male FemaleTo uncheck, set the checked property to false using prop() in jQuery −$('input[id="yourChoice"]:checked').prop("checked", false);ExampleFollowing is the code − Live Demo            Document    Gender    Male     Female    $('input[id="yourChoice"]:checked').prop("checked", false); To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −

How to make checkboxes impossible to check in jQuery?

AmitDiwan
Updated on 03-Oct-2020 13:35:41

244 Views

To make checkboxes impossible to check, set disabled property to true −JavaScriptFollowing is the code −ExampleFollowing is the code − Live Demo            Document    List Of Subject names    MySQL    JavaScript    MongoDB To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −You cannot check the checkbox value above since we have disabled it.

How are the times a user presses the button counted in jQuery?

AmitDiwan
Updated on 03-Oct-2020 13:23:41

171 Views

To count how many times a user presses the button, you need to set counter on button click.ExampleFollowing is the code − Live Demo            Document Press Me The current Value is= 0 var increment = 0; var current = document.getElementById('incrementThisValue'); document.getElementById('pressButton').onclick = (event) => {    current.textContent = ++increment; }; To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −When you press ... Read More

Display tooltip text while hovering a textbox in jQuery

AmitDiwan
Updated on 03-Oct-2020 13:18:42

2K+ Views

For this, use jQuery(selector).toolTip().ExampleFollowing is the code: − Live Demo            Document    Write Your Favourite Subject Name:        jQuery(".demoTooltip").toolTip() To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −When you will hover the mouse inside the text box, you will get your tooltip −Your Favourite Subject may be JavaScript...Displayed in the below screenshot as well −

Slide up and down of a div animates its content - jQuery?

AmitDiwan
Updated on 03-Oct-2020 13:13:52

461 Views

To toggle content, use slideToggle() in JavaScript.ExampleFollowing is the code: − Live Demo            Document    .firstDiv {       display: none;    }    .txtBox {       display: block;    }    Press Me to toggle the text box                              Enter your name:                        function toogleTheTextBox() {       $('#firstDiv').slideToggle(function () {          $('#txtBox').focus();       });    } To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −Press the button “Press Me” to toggle the text box.OutputThe output is as follows −

Looping numbers with object values and push output to an array - JavaScript?

AmitDiwan
Updated on 03-Oct-2020 13:10:05

164 Views

Let’s say the following are our numbers with object values −var numberObject = { 2:90 , 6: 98 }Use Array.from() in JavaScript −var fillThePositionValue = Array.from({length: 15}, (value, index) => numberObject[index+ 1] || "novalue")ExampleFollowing is the code to loop numbers with object values −var numberObject = { 2:90 , 6: 98 } console.log("The actual object is="); console.log(numberObject); var fillThePositionValue = Array.from({length: 15}, (value, index) => numberObject[index+ 1] || "novalue") console.log("After filling the value, the actual object is="); console.log(fillThePositionValue)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo215.js.OutputThe output is as follows ... Read More

JavaScript - Check if value is a percentage?

Disha Verma
Updated on 25-Feb-2025 14:50:05

1K+ Views

To check the value for percentage, use a regular expression. When dealing with user input or processing data in JavaScript, it's important to make sure a value is a valid percentage. This article shows you how to check if a value is a percentage using JavaScript, highlighting a useful method that involves regular expressions. Let's say the following is our value var value="97%"; To check the value for percentage, we are using a regular expression. Using Regular Expression The best way to check if a string is in the correct percentage format is by using regular expressions. ... Read More

How to Implicitly mimic click() in jQuery?

AmitDiwan
Updated on 03-Oct-2020 12:57:04

168 Views

To implicitly mimic click(), you can call a function internally.ExampleFollowing is the code to implicitly mimic click − Live Demo            Document    My Name is John Doe            demo1Data = document.getElementById('demo1').innerHTML    demo1Data = demo1Data.replace('My Name is John Doe', `My Favourite Subject is JavaScript..`)    document.getElementById('demo2').innerHTML = demo1Data    function replaceData() {       document.getElementById('output').innerHTML = 'I live is US.';    } document.getElementById('demo2').querySelector('span').click(); To run the above program, save the file name anyName.html (index.html). Right click on the file and select ... Read More

Advertisements