Laptop and cactus on the left side and coffee on the right side. Image by Megan Rexazin Conde from Pixabay.

Explore focusable, clickable, tabbable or active states

Determining whether an element is interactive or not can be crucial for various purposes, such as improving accessibility, enhancing user experience, testing purpose or debugging issues.

An interactive element is one that can receive focus, be clicked, be active, or be tabbable, allowing users to engage with it in some way. Let’s find out how to determine if an element is focusable or active using JavaScript.

Continue reading “Explore focusable, clickable, tabbable or active states”
Man in a hood on the background of green letters (matrix). On the back there is an inscription: "JavaScript Capitalize First Letter"

Capitalize the first letter in JavaScript

How to capitalize the first letter of a string in JavaScript?

To capitalize the first character of a string in JavaScript while properly handling Unicode characters, you can use the String.prototype.charAt(), String.fromCodePoint() and String.prototype.substring() methods. This ensures that the first character is transformed to uppercase while the rest of the string remains unchanged, accommodating various Unicode character sets effectively, specifically surrogate pairs.

Surrogate pairs are crucial in Unicode because they allow the encoding of characters that fall outside the Basic Multilingual Plane (BMP), which includes code points above U+FFFF. In UTF-16 encoding, these characters are represented using two 16-bit code units: a high-surrogate and a low-surrogate. This mechanism is essential for supporting a wide range of characters, including many emojis and rare scripts, ensuring that applications can display and manipulate all Unicode characters effectively.

Without surrogate pairs, many characters would be inaccessible, limiting the representation of global languages and symbols in digital formats. For example, the character for the “grinning face with smiling eyes” emoji (😄) has a code point of U+1F604. In UTF-16, this is represented as the surrogate pair 0xD83D and 0xDE04.

Continue reading “Capitalize the first letter in JavaScript”
Computer and few dots on the horizontal panel that mimics bookmarks

Bookmarklets for enhancing productivity in the browser

What is a browser bookmarklet?

A bookmarklet is a browser bookmark that contains JavaScript code instead of a web address. When clicked, bookmarklets can perform a wide variety of operations, such as running a search query from selected text or extracting data from a table. They are essentially bookmarks that run JavaScript code on the current page when clicked, allowing users to perform functions on the page they are already on instead of being directed to a new webpage. Bookmarklets are easy to use, portable, and can be shared across different devices. They are generally safer to use than standard programs, as they can only run when clicked and cannot access files on the hard drive.

Continue reading “Bookmarklets for enhancing productivity in the browser”
Example of browser tab with favicon and badge on it

Add a badge to the browser tab favicon using JavaScript

Adding a badge to the favicon using JavaScript can be done by updating the image specified by the <link /> element with a new icon image.

This method involves JavaScript and creating an in-memory canvas element, applying the favicon image, drawing the badge shape and text on top, and then updating the <link /> element’s href attribute with the final composite of the canvas element’s image data as a Base64 encoded string.

Continue reading “Add a badge to the browser tab favicon using JavaScript”