Found 8591 Articles for Front End Technology

How to enable the “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 −

Behavior of + operator in JavaScript to store large numbers?

AmitDiwan
Updated on 03-Oct-2020 12:38:27

3K+ Views

To store large numbers in JavaScript, use BigInt() rather than + operator. If you will use the + operator, then expect loss of precision.Let’s say the following is our large number and we are storing using BigInt() −console.log("Loss of precision with + operator..")ExampleFollowing is the code −var stringValue1="100"; console.log("The integer value="); console.log(+stringValue1); var stringValue2="2312123211345545367"; console.log("Loss of precision with + operator..") console.log(+stringValue2); const storeLongInteger=BigInt("2312123211345545367"); console.log("No loss of precision with BigInt()"); console.log(storeLongInteger);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo212.js.OutputThe output is as follows on console −PS C:\Users\Amit\JavaScript-code> node demo213.js The ... Read More

How to populate select list with jQuery?

AmitDiwan
Updated on 01-Oct-2020 13:42:21

11K+ Views

To populate select list with jQuery, use for loop along with append() and append the options to the already created select.Let’s say we have the following select with options − John David ExampleFollowing is the code to append more number of options using append() − Live Demo            Document           John       David     $(document).ready(function () {    var data = [       { "name": "Bob", "customerName": "Bob" },       { "name": "Mike", "customerName": "Mike" }    ];    for (var index = 0; index

Convert integer array to string array in JavaScript?

AmitDiwan
Updated on 01-Oct-2020 13:38:04

568 Views

To convert integer array to string array, use the map(String) in JavaScript. Let’s say the following is our integer array −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68];Convert integer array to string array −integerValues.map(String);ExampleFollowing is the code −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68]; console.log("The integer array value="); console.log(integerValues); integerValues.map(String); console.log("The string array value="); console.log(integerValues)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo212.js.OutputThe output is as follows in console −PS C:\Users\Amit\JavaScript-code> node demo212.js The integer array value= [    101, 50, 70, 90, ... Read More

Remove json element - JavaScript?

AmitDiwan
Updated on 03-Nov-2023 13:48:38

25K+ Views

Let's say the following is our JSON string −var details = [    {       customerName: "Chris",       customerAge: 32    },    {       customerName: "David",       customerAge: 26    },    {       customerName: "Bob",       customerAge: 29    },    {       customerName: "Carol",       customerAge: 25    } ]To remove JSON element, use the delete keyword in JavaScript.ExampleFollowing is the complete code to remove JSON element −var details = [    {       customerName: "Chris",       ... Read More

How to print div content using jQuery?

AmitDiwan
Updated on 01-Oct-2020 13:33:17

6K+ Views

Let’s say we have the following button −On click of the above button, call the function() with on() −$('#buttonId').on('click', function () {    displayTheData(); })The above function is using the html() to display the following div −    I am inside the div tag... ExampleFollowing is the complete code to print div content − Live Demo            Document           I am inside the div tag...        I am not inside the div tag...            $('#buttonId').on('click', function () ... Read More

Manipulate two selects on page load with jQuery

AmitDiwan
Updated on 01-Oct-2020 13:20:39

478 Views

Let’s say the following is our first select −    John    David    Bob    Mike    Sam    Carol Following is our second select −    David    Mike    Carol We need to remove the options in the first select, which are similar to options in the second select. For this, use val(). Following is the complete code −Example Live Demo              Document           John       David       Bob       Mike       Sam       Carol               David       Mike       Carol        $('#remaining_name > option').each(function (i, el) {       var value = $(el).val();       $('#all_present_name > option[value="' + value + '"]').remove();    }); OutputThe output is as follows −

How to sort date array in JavaScript

AmitDiwan
Updated on 01-Oct-2020 11:09:15

455 Views

Suppose we have an array that contains some dates like this −const arr = [    [ '02/13/2015', 0.096 ],    [ '11/15/2013', 0.189 ],    [ '05/15/2014', 0.11 ],    [ '12/13/2013', 0.1285 ],    [ '01/15/2013', 0.12 ],    [ '01/15/2014', 0.11 ],    [ '02/14/2014', 0.11 ],    [ '03/14/2014', 0.11 ],    [ '01/15/2015', 0.096 ],    [ '07/15/2015', 0.096 ],    [ '04/15/2013', 0.12 ],    [ '04/15/2014', 0.11 ],    [ '05/15/2013', 0.12 ],    [ '06/14/2013', 0.12 ],    [ '06/16/2014', 0.11 ],    [ '07/15/2013', 0.12 ],    [ '07/15/2014', 0.11 ], ... Read More

Recursive string parsing into object - JavaScript

AmitDiwan
Updated on 01-Oct-2020 11:06:42

533 Views

We are required to write a JavaScript function that takes in an array of strings and returns an object corresponding to the strings.For example −If the array is −const arr = [    "country.UK.level.1",    "country.UK.level.2",    "country.US.level.1",    "country.UK.level.3" ];Then the output should be −const output = {    "country": [        {"UK" : {"level" : ["1", "2", "3"]}},        {"US" : {"level" : ["1", "2"]}}   ] } ConditionsStrings stored in the str array will not be sorted and the code should be robust against that.Strings will follow the x.y.x.y... pattern, where x will be ... Read More

How to join JavaScript array of string

AmitDiwan
Updated on 01-Oct-2020 11:03:47

148 Views

We are required to write a JavaScript function that takes in an array of strings. The function should join all the strings of the array, replace all the whitespaces with dash "-", and return the string thus formed.For example: If the array is −const arr = ["QA testing promotion ", " Twitter  ", "Facebook ", "Test"];Then the output should be −const output = "QA-testing-promotion-Twitter-Facebook-Test";ExampleFollowing is the code −const arr = ["QA testing promotion ", " Twitter ", "Facebook ", "Test"]; const joinArr = arr => {    const arrStr = arr.join('');    let res = '';    for(let i = ... Read More

Advertisements