Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Web Development Articles
Page 74 of 801
Lose input hints (get focus) after pressing mouse cursor in a textbox with JavaScript
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 MoreRefresh page after clearing all form fields in jQuery?
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 MoreWhy can't my HTML file find the JavaScript function from a sourced module?
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 MoreIs an empty iframe src valid in JavaScript?
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 MoreRemove and add new HTML Tags with JavaScript?
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 MoreHow would I add a newline in an Unordered List (UL) from JavaScript?
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 MoreGetting an HTML H1 value to JavaScript variable?
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 MoreRemove any text not inside element tag on a web page with JavaScript?
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 MoreHow do I run two or more functions when using 'onclick' JavaScript?
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 MoreDetect the ENTER key in a text input field with JavaScript
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