This JavaScript function selects all elements on a webpage and applies a random color border to each element that doesn’t already have one. If an element already has a border, it removes it. This could be used to visually debug the layout of a webpage.
Open Your Browser’s Favorites/Bookmarks:
- Access your browser’s bookmarks manager. This is usually found in the menu under “Favorites” or “Bookmarks.”
Create a New Bookmark:
- Click on “Add new bookmark” or “New favorite.”
Enter Bookmark Details:
- Name: Give your bookmark a descriptive name, such as “Toggle Borders.”
- URL: In the URL input field, paste the following JavaScript code:
javascript:(function() {
var elements = document.querySelectorAll('*');
var borderApplied = false;
for (var i = 0; i < elements.length; i++) {
if (elements[i].style.border === '') {
var randomColor = '#' + (Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');
elements[i].style.border = '1px solid ' + randomColor;
borderApplied = true;
} else {
elements[i].style.border = '';
borderApplied = false;
}
}
})();
- Save the Bookmark:
Save the new bookmark to your bookmarks bar or a desired folder. - Using the Bookmarklet:
When you want to use the bookmarklet, simply click on the “Toggle Borders” bookmark from your bookmarks bar or folder.
Clicking the bookmark will apply or remove borders on all elements on the current webpage.


1. Self-Executing Anonymous Function (IIFE):

This is an immediately invoked function expression (IIFE). It runs as soon as it is defined. This type of function is used to isolate the variables and functions within it, avoiding pollution of the global namespace.
2. Selecting All Elements on the Page:

document.querySelectorAll('*')selects all elements in the document.elementswill be a collection of all the elements on the page.
3. Initializing the borderApplied Variable:

borderAppliedis a boolean variable indicating whether a border has been applied or not. In this code, it isn’t used further, but it could be utilized for additional functionality.
4. Looping Through All Elements:

- A
forloop is used to iterate through all the selected elements.
5. Checking and Applying Borders:

- It checks if the current element does not have a border
(elements[i].style.border === ''). - If it does not have a border, it generates a random color and applies a 1px solid border with that color.
- If it already has a border, it removes the border
(elements[i].style.border = '';).
6. Generating a Random Color:

– Math.random() * 0xFFFFFF generates a random number between 0 and 0xFFFFFF (equivalent to the decimal number 16777215).
– << 0 performs a bitwise left shift operation, turning the number into an integer.
– .toString(16) converts the number to a string in hexadecimal format.
– .padStart(6, '0') ensures the string has exactly 6 characters, padding with zeros at the start if necessary.
‘#’ + … adds the # symbol in front of the string to form a valid CSS color code.
#javaScript #Bookmarklet #WebDevelopment #CSS #DOM #Manipulation #Front-End #RandomColors #WebDesign #BrowserTools #HTML #Elements #UX #CodeSnippet #Debugging #Styling #Interactive #Tools
ă din fermentarea orzului. Rețeta era foarte simplă: înmuiau în apă orzul prăjit în cuptoare de lut și asteptau până se producea fermentarea. Arheologii americani care au descifrat relicve din anul 1935 au arătat că, acum 6.000 de ani î.C, sumerienii au dezvoltat cel puțin zece rețete de bere – cunoscute sub numele de „Sikaru“. Delta Nilului era deosebit de fertilă, asigurându-i pe egipteni de recolte bogate de orz, ceea ce va duce, în anul 3.500 î.C la o producție de bere deosebit de răspândită. La fel ca locuitorii din Sumeria și Babilon, egiptenii credeau că berea pe care o numeau „Zythum“ era un dar divin. Cu aproape patru mii de ani în urmă, chinezii produceau și ei o băutură fermentată limpede folosind culturile de mei.



