JavaScript Lexical Scoping Issue with New Keyword Constructor

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

146 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

Console Log JavaScript Variables as Related to DOM

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

139 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 −

Uncheck Radio Button from JavaScript to jQuery

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

552 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 −

Make Checkboxes Impossible to Check in jQuery

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

270 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.

Count Button Presses in jQuery

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

190 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 using jQuery

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

481 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 Pushing to an Array in JavaScript

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

183 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

Implicitly Mimic Click in jQuery

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

191 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

Enable Disabled Attribute Using jQuery on Button Click

AmitDiwan
Updated on 03-Oct-2020 12:53:40

2K+ Views

Set the disabled property to true in jQuery −ExampleFollowing is the code − Live Demo         Document             $("#change").click(function (buttonEvent) {     buttonEvent.preventDefault();     $('#showTxtBoxHide').prop("disabled", 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 −The text box property is disabled. To enable, you need to click the button −

Advertisements