AmitDiwan has Published 10740 Articles

Why can't my HTML file find the JavaScript function from a sourced module?

AmitDiwan

AmitDiwan

Updated on 02-Sep-2020 06:14:29

2K+ Views

This may happen if you haven’t used “export” statement. Use “export” before the function which will be imported into the script file. The JavaScript file is as follows which has the file name demo.js.demo.jsconsole.log("function will import"); export function test(){    console.log("Imported!!!"); }Here is the “index.html” file that imports the above ... Read More

Refresh page after clearing all form fields in jQuery?

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:30:34

2K+ Views

To refresh page, use the location.reload() in JavaScript. The sample JavaScript code is as follows −Example Live Demo Document UserName: Password: Refresh Page    $('#RefreshPage').click(function() {       location.reload();   ... Read More

Lose input hints (get focus) after pressing mouse cursor in a textbox with JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:27:37

456 Views

Let’s say the following is our input text −StudentName:To lose input hints on pressing mouse cursor, use onFocus and onBlur concept.Example Live Demo Document StudentName:    function guessFocus() {       if (this.value == this.defaultValue)         ... Read More

How to inherit CSS properties of parent Element using JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:23:55

466 Views

You can use classList.add() along with append(). Use the document.createElement() to create a new div and the classList.add() would add the CSS class.(.class selector).Example Live Demo Document    .add-all-subject {       display: grid;       height: 100px;       width: 100px;   ... Read More

How to capitalize the first letter of each word in a string using JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:18:46

3K+ Views

At first, you need to split() the string on the basis of space and extract the first character using charAt(). Use toUpperCase() for the extracted character.Examplefunction capitalizeTheFirstLetterOfEachWord(words) {    var separateWord = words.toLowerCase().split(' ');    for (var i = 0; i < separateWord.length; i++) {       separateWord[i] = ... Read More

Remove same values from array containing multiple values JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:14:07

218 Views

Let’s say the following is our array with similar values −const listOfStudentName = ['John', 'Mike', 'John', 'Bob', 'Mike', 'Sam', 'Bob', 'John'];To remove similar values from array, use the concept of set(). Following is the code −Exampleconst listOfStudentName = ['John', 'Mike', 'John', 'Bob', 'Mike', 'Sam', 'Bob', 'John']; console.log("The value="+listOfStudentName); const doesNotContainSameElementTwice ... Read More

Check if value is empty in JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:13:00

21K+ Views

Use the condition with “” and NULL to check if value is empty. Throw a message whenever ua ser does not fill the text box value.Example Live Demo Document USERNAME:    function checkingUserName() {       ... Read More

Is it possible to display substring from object entries in JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:10:22

306 Views

Yes, you can use Object.fromEntries() along with substr(). Under substr(), mention the index from where to begin the substring and the length.Exampleconst originalString = {    "John 21 2010" :1010,    "John 24 2012" :1011,    "John 22 2014" :1012,    "John 22 2016" :1013, } const result = Object.fromEntries(Object.entries(originalString). ... Read More

Convert HTML table to array in JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:08:21

5K+ Views

Get data from tag using find() and store that data into array using push(). Let’s say the following is our table − Name Age John23 David26 Let’s fetch the data from and store in an array. Following is the complete code −Example Live Demo ... Read More

Count number of occurrences for each char in a string with JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Sep-2020 12:04:49

2K+ Views

Take an array to store the frequency of each character. If similar character is found, then increment by one otherwise put 1 into that array.Let’s say the following is our string −var sentence = "My name is John Smith";Following is the JavaScript code to count occurrences −Examplevar sentence = "My ... Read More

Advertisements