Sunday, October 24, 2021

Call Back Functions in Javascript

 <!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Call Back Function</title>

</head>

<body>

<h1>Students List</h1>

<ul id="name"></ul>

<script type="text/javascript">

const students = [

             

             {name : "atul", subject : "Computer Science"},

             {name : "ashish", subject : "Computer Network"}


]


function setStudents(something, callBack) {

               setTimeout(function(){

                    students.push(something);

                    console.log("Student Updated");

                    callBack();

               }, 3000);

}

        

        function getStudents() {

        setTimeout(function(){

               var str = "";

               students.forEach(function(args){

                str = str + `<li>${args.name}</li>`

               });

               document.getElementById('name').innerHTML = str;

               console.log("Hey showing Students");

        }, 1000)

        }


        var jayega = {name : "pradeep", subject : "Android"}

        setStudents(jayega, getStudents);

      


</script>


</body>

</html>


yaha par setStudent getStudent ko rok kar rakhega jabtak ki wo khud execute nahi ho jata



Tuesday, October 19, 2021

Setting cookies with javascript

 document.cookie

//It will show all the cookie stored with refrence to website

to Set Cookie

document.cookie = "name=atul";

document.cookie = "age=12";

 document.cookie

'name=atul;age=12' //Cookie will be in String Form

add split function to split it in the form of array;

Copy Text By clicking on Button

1. First of all create input type text add attribute readonly="readonly" to it

2.Get that input element by id or whatever ex. x =  document.getElementById("toCopy");

3. Add x.select(); function to select the text inside the input element

4. Call document function ex : document.execCommand("copy");

Here we go selected text at line number 3 will be copied




document.getElementById("toCopy");

<input readonly=​"readonly" style=​"font-size:​15px;​text-align:​left;​background:​none;​border:​none;​color:​white;​padding:​10px;​pointer:​cursor;​outline:​none;​width:​100%;​" id=​"toCopy" value=​"https:​/​/​dropshare.in/​3433gh">​

document.getElementById("toCopy").select();

undefined

document.getElementById("toCopy").sele

undefined

document.getElementById("toCopy").select();

undefined

document.execCommand("copy");

true

Setting Cookie with javaScript and reading

 <!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>

</title>

</head>

<body>

       <script type="text/javascript">

        document.cookie = "name=autl";

        document.cookie = "course=bca";

        document.cookie = "age=21";

        console.log(document.cookie);


        var x = document.cookie;

        var y = x.split(";");

        console.log(y);


        y.map(function(args) {

        t = args.split("=");

        console.log(t);

        })

       </script>

</body>

</html>

Monday, October 18, 2021

LocalStorage JavaScript

 <!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

</head>

<body>

<script>

//Add Key Value pair inside local Storage

       localStorage.setItem('Name', 'Atul');    

       localStorage.setItem('Name2', 'Atul2'); 


       //Getting an item from the local Storage

       let name = localStorage.getItem('Name');

       //Clears the entire local Storage

       // localStorage.clear();

       console.log(name); 

  //Removing A single item from Storage key value pair

  localStorage.removeItem('Name2');


//Adding Array to localStorage...Normally if you save Browser will convert it into string

let impArray = ['Adrak', 'Pyaz', 'bhindi'];

localStorage.setItem('Sabji', JSON.stringify(impArray));


//Getting that saved Array String and converting it to normal Array


let x = localStorage.getItem('Sabji');

let y = JSON.parse(x);

console.log(y);

//['Adrak', 'Pyaz', 'bhindi'] now we can performe all operation related to JS Array

//Array ke sath fayeda hoga string manipulation mein



//Clearing all localStorage

localStorage.clear();




</script>

</body>

</html>

Priority queue deleting elements after ascending inputs Gaand Fadd

 using namespace std; #include<iostream> #define N 5 class pq { public:     int* arr;     int front;     int rear;     pq() {         ...