Web Development Articles

Page 74 of 801

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

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 469 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 Document StudentName:    function guessFocus() {       if (this.value == this.defaultValue)          this.value = '';    }    function guessBlur(event) {       if (this.value == '')       this.value = this.defaultValue;    }    var event = document.getElementById('studentName');    event.onfocus = guessFocus;    event.onblur = guessBlur; To run the above program, save the file name “anyName.html(index.html)” and right ...

Read More

Refresh page after clearing all form fields in jQuery?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

To refresh page, use the location.reload() in JavaScript. The sample JavaScript code is as follows −Example Document UserName: Password: Refresh Page    $('#RefreshPage').click(function() {       location.reload();    }); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −After filling the form, the snapshot is as follows −When you click the button “Refresh Page”, the page will refresh and the following output is visible −

Read More

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

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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 function −index.htmlExample Document    import { test } from "./demo.js"    test(); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code ...

Read More

Is an empty iframe src valid in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

For empty iframe src, use the element and set it like the following for an empty src −Example Document To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −

Read More

Remove and add new HTML Tags with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 791 Views

To remove and add new HTML tags, use the concept of hide() and show().Let’s say the following are our buttons −Click Me To hide above content Click Me To show above content To remove and add tags on button clicks, use hie() and show() −$(document).ready(function(){    $("#hide").click(function(){       $("h1").hide();    });    $("#show").click(function(){       $("h1").show();    }); });Example Document Test JavaScript Click Me To hide above content Click Me To show above content    $(document).ready(function(){       $("#hide").click(function(){         ...

Read More

How would I add a newline in an Unordered List (UL) from JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 386 Views

To add a newline in Unordered List, use the document.querySelector().append(). Following is the code −Example Document    h1{       font-size: 2.50rem;    }    h2, label{       font-size: 1.50rem;    } Adding Name Demo Enter The Name: Save List Of Name    const buttonName = document.querySelector('.btnName')    const addName = e => {       let nameTxt = document.querySelector('.txtName'),       name = nameTxt.value.trim()       if (name) {          let tagLi = document.createElement('li') ...

Read More

Getting an HTML H1 value to JavaScript variable?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 4K+ Views

To get the value of H1 to JavaScript variable, you can use −document.getElementById().innerHTML.Let’s say the following is our H1 heading − This is the demo program of JavaScript ........Now, let’s get the H1 value using the below code −Example Document This is the demo program of JavaScript ........    var data=document.getElementById('demo').innerHTML;    console.log("The data is="+data); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −

Read More

Remove any text not inside element tag on a web page with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

To remove text, use the concept of remove(). Use filter to get the content not inside element tag.Let’s say the following is our HTML −Demo Program This is also Demo ProgramAnd we have to remove “This is also Demo Program” since it is not under element tag. For that, the compete code is as follows using filter() and remove() −Example Document Demo Program This is also Demo Program    $('body').contents().filter(function(){       return this.nodeType != 1;    }).remove(); To run the above program, save the file name ...

Read More

How do I run two or more functions when using 'onclick' JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 626 Views

Let’s first set a button − Call Above, we have set a function under “onclick” to call two other functions −function callTwoOtherFunctions(){    fun1();    fun2(); }In this way, work around the fun1() and fun2() as in the complete code below −Example Document Call    function callTwoOtherFunctions(){       fun1();       fun2();    }    function fun1(){       console.log("Function1()")    }    function fun2(){       console.log("Function2()")    } To run the above program, save the file name “anyName.html(index.html)” and ...

Read More

Detect the ENTER key in a text input field with JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 6K+ Views

You can use the keyCode 13 for ENTER key. Let’s first create the input −Now, let’s use the on() with keyCode to detect the ENTER key. Following is the complete code −Example Document    $("#txtInput").on('keyup', function (event) {       if (event.keyCode === 13) {          console.log("Enter key pressed!!!!!");       }    }); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will ...

Read More
Showing 731–740 of 8,006 articles
« Prev 1 72 73 74 75 76 801 Next »
Advertisements