Create a Tooltip with CSS

Arjun Thakur
Updated on 24-Jun-2020 06:53:17

416 Views

You can try to run the following code to create a tooltip visible on mouse over. Use the visibility propertyExampleLive demo           #mytooltip #mytext {          visibility: hidden;          width: 100px;          background-color: black;          color: #fff;          text-align: center;          border-radius: 3px;          padding: 10px 0;          position: absolute;          z-index: 1;       }       #mytooltip:hover #mytext {          visibility: visible;       }               Hover the mouse over me          My Tooltip text          

Specify the Speed Curve of Animation with CSS

George John
Updated on 24-Jun-2020 06:51:50

363 Views

Use the animation-timing-function to set the speed curve of the Animation. You can try to run the following code to achieve thisExampleLive Demo                    div {             width: 150px;             height: 200px;             position: relative;             background-color: yellow;             animation-name: myanim;             animation-duration: 2s;             animation-direction: alternate-reverse;             animation-iteration-count: 3;          }          @keyframes myanim {             from {left: 100px;}             to {left: 200px;}          }          #demo1 {animation-timing-function: ease;}          #demo2 {animation-timing-function: ease-in;}                     ease effect       ease-in effect    

Negative Lookbehind Equivalent in JavaScript

Ankith Reddy
Updated on 24-Jun-2020 06:45:12

108 Views

For a negative look-behind in JavaScript, use the following −(^|[^\])"To replace double quotes, you can use the following −str.replace(/(^|[^\])"/g, "$1'")

Strict Comparison in JavaScript Switch Statement

Priya Pallavi
Updated on 24-Jun-2020 06:44:25

173 Views

To get out of the confusion regarding strict comparison, try to run the following code snippet in JavaScript −Exampleswitch(1) {    case '1':       alert('Switch comparison: Not Strict.');       break;    case 1:       alert('Switch comparison: Strict.');       break;    default:       alert(‘Default’); }

Automated Unit Testing with JavaScript

Chandu yadav
Updated on 24-Jun-2020 06:43:52

255 Views

To perform unit testing in JavaScript, use Unit.js. It is a cross-platform open-source unit testing framework.ExampleLet’s say the following in your test code −var example = ‘Welcome’; test.string(example) .isEqualTo(‘Welcome’);The function demo() displays a suit of tests, whereas demo1() is an individual test specification,demo('Welcome’, function() {    demo1('Welcome to the website', function() {       var example = ‘Welcome’;       test.string(example)       .isEqualTo(‘Welcome’);    }); });

Display JavaScript Variables in HTML Without document.write

Sravani S
Updated on 24-Jun-2020 06:42:02

471 Views

Use Element.innerHTML in JavaScript to display JavaScript variables in an HTML page without document.write.You can try to work through the following code snippet −var $myName = document.querySelector('.name'); var $jsValue = document.querySelector('.jsValue'); $myName.addEventListener('input', function(event){    $jsValue.innerHTML = $myName.value; }, false);

Why is +1 + 23 + 4 in JavaScript?

Arjun Thakur
Updated on 24-Jun-2020 06:41:33

113 Views

The JavaScript's + operator is used to add two numbers or join two strings. However, use the contact() method to join two arrays to get a new one. For example,[50, 70].concat([90, 100])The above prints,[50, 70, 90, 100]Let’s see your example. The + operator concats strings, and converts the arrays to strings −[1,2] + [3,4] '1,2' + '3,4' 1,23,4Or as mentioned above, use concat(),[1,2].concat([3,4]) [1,2,3,4]

Use JavaScript Array.sort() Method for Shuffling

Nikitha N
Updated on 24-Jun-2020 06:40:54

108 Views

Yes, you can use the JavaScript Array.sort() method for shuffling. Let’s see howExamplefunction shuffleDisplay(arr) {    var tmp, current;        // calculating length    var top = arr.length;    if(top) while(--top) {       current = Math.floor(Math.random() * (top + 1));       tmp = arr[current];       arr[current] = arr[top];       arr[top] = tmp;    }    return arr; }

Fix Array indexOf in JavaScript for Internet Explorer Browsers

Ramu Prasad
Updated on 24-Jun-2020 06:37:02

480 Views

To fix Array.indexOf() for Internet Explorer web browser, use the following −jQuery.inArray( value, array [, fromIndex ] )Add the following,

Convert Image to Base64 String Using JavaScript

Arjun Thakur
Updated on 24-Jun-2020 06:36:26

638 Views

To convert the image into a base64 string using JavaScript, use the FileReader API. You can try to run the following code to get base64string for an image −Example                    function toDataURL(url, callback) {             var httpRequest = new XMLHttpRequest();             httpRequest.onload = function() {                var fileReader = new FileReader();                   fileReader.onloadend = function() {                      callback(fileReader.result);                   }                   fileReader.readAsDataURL(httpRequest.response);             };             httpRequest.open('GET', url);             httpRequest.responseType = 'blob';             httpRequest.send();          }          toDataURL('https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg', function(dataUrl) {          document.write('Result in string:', dataUrl)       })          

Advertisements