Following is the code for accessing a parent element using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: #8a2be2; } .parent1, .parent2, .parent3 { display: inline-block; margin: 10px; } .child1, .child2, .child3 { width: 70px; height: 70px; } .child1 { background-color: red; ... Read More
Following is the code for checking whether a button is clicked using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: blueviolet; } Checking whether a Button is clicked using JavaScript CLICK HERE Click on the above button to check if the button is clicked let BtnEle = document.querySelector(".Btn"); let resEle = document.querySelector(".result"); let clickCount = 0; BtnEle.addEventListener("click", () => { clickCount++; resEle.innerHTML = "The button has been clicked " + clickCount + " times "; }); OutputOn clicking the button 5 times −
Following is the code to display an alert for form’s unsaved changes in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } input { margin: 10px; } Alert for unsaved changes in form Username Password SUBMIT function pageUnload() { return "The data on this page will be lost if you leave"; } OutputIf we click on the reload button then the following warning will be shown −
Following is the code to find the coordinates of every link in a page using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Coordinates of every link in a page google.com facebook.com yahoo.com CLICK HERE Click on the above button to display the link coordinates let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let links = document.getElementsByTagName("a"); BtnEle.addEventListener("click", () ... Read More
Following is the code to circle coordinates to array in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-weight: 500; font-size: 18px; color: blueviolet; } Circle coordinates to array CLICK HERE Click on the above button to generate the circle coordinates let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let xCoords = []; let yCoords = []; function circleCoordinates(radius, steps, ... Read More
Following is the code to retrieve the text contents of the user selection using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 20px; font-weight: 500; color: rebeccapurple; } Retrieve the text contents of the user selection Here is some text inside the div SELECT Click on the above button to display the text selected by the user let resEle = document.querySelector(".result"); ... Read More
Following is the code to select and deselect text inside an element using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Select and Deselect Text Inside an Element Here is some text inside the div SELECT DESELECT Click on the above button to select/de-select text inside the div let resEle = document.querySelector(".result"); let BtnEle = document.querySelectorAll(".Btn"); BtnEle[0].addEventListener("click", () => { window.getSelection().selectAllChildren(resEle); }); BtnEle[1].addEventListener("click", () => { window.getSelection().removeAllRanges(); }); OutputThe above code will produce the following output −On clicking the ‘SELECT’ button −On clicking the ‘DESELECT’ button −
Following is the code to de-select text on HTML page −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: rebeccapurple; } De-select text on HTML page Here is some text inside the div CLICK HERE Click on the above button to deselect everything on this page let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { window.getSelection().removeAllRanges(); }); OutputThe above code will produce the following output −Selecting some text on the page −On clicking the ‘CLICK HERE’ button −
In this problem, we are given an array of string. Our task is to create a c program to sort an array of name or string. This program will sort all the names we have given in the input in ascending alphabetical order.Let’s take an example to understand the problem, InputnamesArray = ["Rishabh", "Jyoti", "Palak", "Akash"]Output["Akash", "jyoti", "palak", "Rishabh"]To solve this we will use the qsort() function of the standard template library as we know sorting of integer values the thing that changes here is we are considering string for comparison instead of integer values.So, the comparator that is used ... Read More
In this problem, we are will create a C program to simulate non-deterministic Finite automata (NFA).NFA (Non-deterministic Finite automata) finite state machine that can move to any combination of states for an input symbol i.e. there is no exact state to which the machine will move.Formal definition of NDFA −NFA / NDFA (Non-deterministic Finite automata) can be represented by 5-tuple (Q, ∑, δ, q0, F) where −Q is a finite set of states.∑ is a finite set of symbols called the alphabets.δ is the transition function where d: Q × ∑ → 2Q (Here the power set of Q (2Q) ... Read More