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
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 −
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 −
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.
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
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 −
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 −
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
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
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 −
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP