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 73 of 801
Extract the value of the <text> to a variable using JavaScript?
To extract the value of the , use −document.getElementById(“yourTextIdValue”).textContentExample Document This is the JavaScript.... var originalText = document.getElementById("myText").textContent; console.log(originalText); To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.OutputThis will produce the following output display the value −
Read MoreParse JSON in JavaScript to display a specific name/value pair?
To parse JSON, use parseJSON() and for displaying a specific pair, use the $.each() function.Let’s say the following is our JSON, which is parsed −const APIData = '[{"Name":"John", "Age":21}, {"Name":"David", "Age":24}, {"Name":"Bob", "Age" :20}]'; const getObject = jQuery.parseJSON(APIData);Now, let’s see the complete code and fetch the “Name” pairs −Example Document const APIData = '[{"Name":"John", "Age":21}, {"Name":"David", "Age":24}, {"Name":"Bob", "Age":20}]'; const getObject = jQuery.parseJSON(APIData); $.each(getObject, function (k, obj) { console.log(obj['Name']); }); To run the above program, save the file name “anyName.html(index.html)” ...
Read MoreHow do I display only the visible text with jQuery?
To display only the visible text, use the concept of − visible selector in jQuery. It selects the element currently visible. Following is the code −Example Document Test Class Demo class $('#myDiv').children(":visible").text() 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.This will produce the following output displaying the visible text −
Read MoreHow to find out what character key is pressed in JavaScript?
To find out which characters key is pressed, use the window.event along with keyCode. Following is the code −Example Document function keyPressName(myEventKeyName){ var pressedKey; if(window.event){ pressedKey = myEventKeyName.keyCode; } else if(myEventKeyName.which) { pressedKey = myEventKeyName.which; } alert(String.fromCharCode(pressedKey)); } 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 ...
Read MoreSimplest way to detect keypresses in JavaScript?
The easiest way to detect keypresses in JavaScript, use the onKeyPress event handler −document.onkeypressThe key press is matched with the keyCode property, which returns the Unicode character code of the key that triggered the onkeypress event.Example Document document.onkeypress = function (eventKeyName) { eventKeyName = eventKeyName || window.event; if(eventKeyName.keyCode==13){ console.log('You have pressed enter key'); } else { alert(String.fromCharCode(eventKeyName.keyCode)) } }; To run the above program, save the file name “anyName.html(index.html)” ...
Read MoreStore and retrieve arrays into and from HTML5 data attributes with jQuery?
To store and retrieve arrays into and from data attributes, use the data() method in jQuery. Following is the syntax −var anyVariableName= $('#yourIdName).data('yourJavscriptArrayName');Following is the jQuery code −Example Document var value = $('#test').data('details'); alert(value); 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 MoreHow to get value from the first checkbox which is not hidden in jQuery?
To get value from the first checkbox, which is not hidden, use the :visible selector. Following is the code −Example >Document .notShown { display: none; } var v=$('input:checkbox:checked:visible:first').val(); console.log(v); 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.This will produce the following output displaying the visible value “second” in console −
Read MoreConvert HTML table to array in JavaScript?
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 Document .notShown { display: none; } Name Age John23 David26 var convertedIntoArray = []; $("table#details tr").each(function() { var rowDataArray = []; ...
Read MoreCheck if value is empty in JavaScript
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 Document USERNAME: function checkingUserName() { var username = document.forms["register"]["username"].value; if (username == null || username == "") { alert("Please enter> the username. Can’t be blank or empty !!!"); return false; } } To run the above program, save the ...
Read MoreHow to inherit CSS properties of parent Element using JavaScript?
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 Document .add-all-subject { display: grid; height: 100px; width: 100px; grid-template-columns: 2fr 2fr 2fr 2fr 2fr; grid-template-rows: 2fr; grid-column-gap: 5.9rem; grid-row-gap: 2rem; color: red; border: 2px solid red; } Add Subjects const addSubjectArea = document.getElementById("add-subject"); ...
Read More