Web Development Articles

Page 73 of 801

Extract the value of the <text> to a variable using JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 782 Views

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 More

Parse JSON in JavaScript to display a specific name/value pair?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 618 Views

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 More

How do I display only the visible text with jQuery?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 561 Views

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 More

How to find out what character key is pressed in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 720 Views

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 More

Simplest way to detect keypresses in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 331 Views

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 More

Store and retrieve arrays into and from HTML5 data attributes with jQuery?

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

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 More

How to get value from the first checkbox which is not hidden in jQuery?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 894 Views

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 More

Convert HTML table to array in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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 Document    .notShown {       display: none;    } Name Age John23 David26    var convertedIntoArray = [];    $("table#details tr").each(function() {       var rowDataArray = []; ...

Read More

Check if value is empty in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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 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 More

How to inherit CSS properties of parent Element using JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 478 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 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
Showing 721–730 of 8,006 articles
« Prev 1 71 72 73 74 75 801 Next »
Advertisements