console.time(‘myTimer’); // Your code here console.timeEnd(‘myTimer’); // Outputs the time taken article
All posts by vigdor
Quick Positioning with inset in CSS
/* Verbose way */ div { position: absolute; top: 0; left: 0; bottom: 0; right: 0; } /* With inset */ div { position: absolute; inset: 0; } article
Hiding DOM Elements with Ease
<p hidden>I’m invisible!</p> No need to rely solely on JavaScript to hide elements. Utilize the native HTML hidden attribute. This has a similar effect to display: none; in CSS, making the element disappear. article
Checking Network Speed
if (navigator.connection) { const downlink = navigator.connection.downlink; console.log(`Current download speed: ${downlink} Mbps`); } else { console.log(“Network Information API not supported”); } article
Preventing Text Pasting
<input type=”text”></input> <script> const input = document.querySelector(‘input’); input.addEventListener(“paste”, function(e){ e.preventDefault() }) </script> article
3 Ways To Create HTML Element In JavaScript
Using Just createElement() Create a div HTML Element in JavaScript by calling the createElement() method on the document object. This method takes an argument which will be the HTML Element. In this case…div. const box = document.createElement(“div”); box.id = “box”; document.body.appendChild(box); Assign it to the constant called box. Set the id property of box to ‘box‘. Add it to the DOM hierarchy by calling appendChild() on the document.body object with an argument box. Let’s […]
Prevent text selection CSS
User-select property – prevent text selection To prevent text selection, you can add CSS: p { -webkit-user-select: none; /* Safari */ -ms-user-select: none; /* IE 10 and IE 11 */ user-select: none; /* Standard syntax */ } on specific class .prevent-select {-webkit-user-select: none; /* Safari */ -ms-user-select: none; /* IE 10 and IE 11 */ […]
Set opacity to background image without affecting children (CSS)
background-image: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,.5)), url(‘https://cataas.com/cat’) article
Web Bluetooth API
This API allows you to connect to and communicate with Bluetooth-enabled devices directly from the browser. With this API, you can create web-based apps that control IoT devices, smart homes, wearables, and other Bluetooth-enabled products.
Web Speech API
This API allows you to add speech recognition and synthesis capabilities to your website. With this API, you can create voice-activated interfaces, enable speech-to-text transcription, and even generate synthesized speech output.