Close List Items with JavaScript

AmitDiwan
Updated on 12-May-2020 11:23:43

596 Views

To close list items with JavaScript, the code is as follows −Example Live Demo    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    * {       box-sizing: border-box;    }    ul {       list-style-type: none;       padding: 0;       margin: 0;    }    ul li {       border: 1px solid rgb(221, 221, 221);       background-color: #5a5cec;       color: white;       padding: 12px;       text-decoration: none;       font-size: 18px; ... Read More

Create Chat Message with CSS

AmitDiwan
Updated on 12-May-2020 10:55:35

441 Views

To create a chat message with CSS, the code is as follows −Example Live Demo    body {       margin: 0 auto;       max-width: 800px;       padding: 0 20px;       font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;    }    .message {       font-size: 18px;       font-weight:500;       border: 2px solid #dedede;       background-color: #55e4a8;       color:rgb(0, 0, 0);       border-radius: 12px;       padding: 10px;       margin: 10px 0;    }    .darker ... Read More

Create Typing Effect with JavaScript

AmitDiwan
Updated on 12-May-2020 10:50:45

287 Views

To create a typing effect with JavaScript, the code is as follows −Example Live Demo    body{       font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;    }    button{       padding:10px;       font-size: 18px;       background-color: rgb(128, 19, 218);       color:white;       border:none;    }    .heading{       color:crimson;    } typeText Click me    document.querySelector('.typeButton').addEventListener('click',typeText);    var i = 0;    var text = 'This text is currently being typed across... It is still typing..';    var speed = 50;    function typeText() {       if (i < text.length) {          document.querySelector('.heading').innerHTML += text.charAt(i);          i++;          setTimeout(typeText, speed);       }    } OutputThe above code will produce the following output −On clicking the “Click me” button −

Create Countdown Timer with JavaScript

AmitDiwan
Updated on 12-May-2020 10:48:00

681 Views

To create a countdown timer with JavaScript, the code is as follows −Example Live Demo    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .timer {       text-align: center;       font-size: 60px;       margin-top: 0px;       color: white;       background-color: rgb(100, 38, 214);    } Countdown Timer Example    var countDownDate = new Date("June 5, 2022 11:27:15").getTime();    var timeClear = setInterval(function() {       var now = new Date().getTime();       var ... Read More

Use Icons to Create Animated Effects with JavaScript

AmitDiwan
Updated on 12-May-2020 10:45:00

359 Views

To use icons to make animated effect, the code is as follows −Example Live Demo    #user {       font-size: 60px;       color:rgb(106, 33, 201);    }    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;       padding: 20px;    } Animating Icon example    function userShift() {       var userEle;       userEle = document.getElementById("user");       userEle.innerHTML = "";       setTimeout(function() {          userEle.innerHTML = "";       }, 1000);       setTimeout(function() {          userEle.innerHTML = "";       }, 2000);    }    userShift();    setInterval(userShift, 4000); OutputThe above code will produce the following output −

Fetch Random Value Using Map-Reduce in MongoDB

AmitDiwan
Updated on 12-May-2020 09:02:03

305 Views

For random value with Map Reduce, use mapReduce() concept along with Math.random(). Let us create a collection with documents −> db.demo651.insertOne({Value:10}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e9f0330e3c3cd0dcff36a57") } > db.demo651.insertOne({Value:20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e9f0332e3c3cd0dcff36a58") } > db.demo651.insertOne({Value:30}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e9f0335e3c3cd0dcff36a59") } > db.demo651.insertOne({Value:40}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e9f0337e3c3cd0dcff36a5a") } > db.demo651.insertOne({Value:50}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e9f0339e3c3cd0dcff36a5b") } > db.demo651.insertOne({Value:60}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e9f033be3c3cd0dcff36a5c") } > db.demo651.insertOne({Value:70}); {    "acknowledged" : true,    "insertedId" ... Read More

Query Only the Field Name and Display ID in MongoDB

AmitDiwan
Updated on 12-May-2020 08:57:02

878 Views

To query only the field name, set fieldName to 0 i.e. the fieldName to hide. Let us create a collection with documents −> db.demo650.insertOne({_id:101, details:{Name:"Chris", Age:21}}); { "acknowledged" : true, "insertedId" : 101 } > db.demo650.insertOne({_id:102, details:{Name:"Bob", Age:22}}); { "acknowledged" : true, "insertedId" : 102 } > db.demo650.insertOne({_id:103, details:{Name:"Sam", Age:20}}); { "acknowledged" : true, "insertedId" : 103 } > db.demo650.insertOne({_id:104, details:{Name:"Robert", Age:24}}); { "acknowledged" : true, "insertedId" : 104 }Display all documents from a collection with the help of find() method −> db.demo650.find();This will produce the following output −{ "_id" : 101, "details" : { "Name" : "Chris", "Age" : ... Read More

MongoDB Aggregation: Group and Remove Duplicate Array Values

AmitDiwan
Updated on 12-May-2020 08:55:19

3K+ Views

Use MongoDB aggregate for this and within that, use $group. Let us create a collection with documents −> db.demo649.insertOne( ...    { "_id" : 101, "Names" : [ "John", "Bob", "Bob", "Robert" ], "CountryName" : "US" } ... ); { "acknowledged" : true, "insertedId" : 101 } > > db.demo649.insertOne({ "_id" :102, "Names" : [ "John", "Robert" ], "CountryName" : "UK"}); { "acknowledged" : true, "insertedId" : 102 }Display all documents from a collection with the help of find() method −> db.demo649.find();This will produce the following output −{ "_id" : 101, "Names" : [ "John", "Bob", "Bob", "Robert" ], "CountryName" ... Read More

Create and Display Newly Created Database in MongoDB

AmitDiwan
Updated on 12-May-2020 08:53:29

127 Views

To create a new database, you need to use the USE command as in the below syntax −use yourDatabaseName;To show all databases, you need to use show command. The syntax is as follows −show dbs;Let us implement the above syntax in order to create database −> use onlinecustomertracker; switched to db onlinecustomertrackerIn order to display the newly created database, you need to create collection. Following is the query −> db.example.insert({Value:10}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.example.find();This will produce the following output −{ "_id" : ObjectId("5e9dafade3c3cd0dcff36a4f"), "Value" : 10 ... Read More

Perform Nested Document Value Search in MongoDB

AmitDiwan
Updated on 12-May-2020 08:50:43

149 Views

For searching value, use $match in MongoDB. Let us create a collection with documents −> db.demo648.insertOne( ...    { ...       StudentInformation: ...       [ ...          { ...             Name:"John", ...             CountryName:"US" ...          }, ...          { ...             Name:"David", ...             CountryName:"AUS" ...          }, ...          { ...             Name:"Chris", ... ... Read More

Advertisements