AmitDiwan has Published 10744 Articles

How to convert JSON text to JavaScript JSON object?

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:57:01

855 Views

The JSON parse() method is used for converting a JSON text to a JavaScript object.Following is the code for converting JSON text to JavaScript JSON object −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }   ... Read More

Add oninput attribute to HTML element with JavaScript?

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:54:17

595 Views

For this, use the concept of document.getElementById() along with addEventListener(). Following is the JavaScript code −Example Live Demo Document Enter the value:    document.getElementById('enterValue').addEventListener("input", function () {       console.log('you have entered the value');    }); ... Read More

How to create a JSON object in JavaScript? Explain with an example.

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:54:14

466 Views

Following is the code to create a JSON object in JavaScript.Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } ... Read More

Get number from user input and display in console with JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:52:55

3K+ Views

You can use # to get the value when user clicks the button using document.querySelector(“”); Following is the JavaScript code −Example Live Demo Document Example: choose a number between 1 to 100 Give a number: ... Read More

How to create a constant array in JavaScript? Can we change its values? Explain.

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:51:41

2K+ Views

To create a const array in JavaScript we need to write const before the array name. The individual array elements can be reassigned but not the whole array.Following is the code to create a constant array in JavaScript.Example Live Demo Document    body {     ... Read More

Random color generator in JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:50:51

1K+ Views

Following is the syntax to generate random color in JavaScript −$("#yourIdName").css("background-color", yourCustomFunctionNameToGetRandomColor());Following is the JavaScript code −Example Live Demo Document Click the button to get random color    //The getColorCode() will give the code every time.    function getColorCode() ... Read More

Hide div that contains specific text with JavaScript?

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:46:35

1K+ Views

At first, you need to extract the extract the div class with the help of getElementsByClassName() and iterate over the for loop and use the OR condition to show the specific text.Also, set yourDiv.style.display=’none’.Following is the JavaScript code −Example Live Demo Document ... Read More

How to preview an image before it is uploaded in JavaScript?

AmitDiwan

AmitDiwan

Updated on 16-Jul-2020 06:43:59

228 Views

To upload an image, use FileReader() in JavaScript. Following is the JavaScript code −Example Live Demo Document    function readImage(fileInput) {       if (fileInput.files && fileInput.files[0]) {          var takingInputFile = new ... Read More

Explain the Error Name Values in JavaScript with examples.

AmitDiwan

AmitDiwan

Updated on 15-Jul-2020 14:14:45

329 Views

The error name value is used for setting or returning the error name. The error name can return the below values.Sl.NoError Name & Description1EvalErrorIt represents an error in the eval() function2RangeErrorIt happens when a numeric value is out of its range3ReferenceErrorIt happens when an illegal reference has occured4SyntaxErrorIt represents a ... Read More

Explain try and catch statements in JavaScript with examples.

AmitDiwan

AmitDiwan

Updated on 15-Jul-2020 14:11:20

222 Views

The try statement allows us execute a block of code and test for errors. Those errors are then caught and handle by the catch statement.Following is the code for try and catch statement in JavaScript −Example Live Demo Document    body {       font-family: ... Read More

Advertisements