As far as I understand you have several classes with the float
set on them.
So, in that case the only way I can think of is using querySelectorAll
.
Example:
For the class search (e.g. <div class="f"></div>
or <div class="a"></div>
)
const elementsToHighlight = document.querySelectorAll(".f, .a");
elementsToHighlight.forEach(function (elem) {
elem.classList.add("highlighted");
});
For inline style you can use the following code (we search for every HTML element that has its float
property set via inline style) (e.g. <div style="float: left;"></div>
or <div style="float: right;"></div>
). Note that style attribute can have as many properties set as it desired that's why we use an asterisk to account for this case.
const elementsToHighlight = document.querySelectorAll('[style*="float"]');
elementsToHighlight.forEach(function (elem) {
elem.classList.add("highlighted");
});
Function that recursively traverses all HTMLElements in the DOM, checks their style and if HTMLElement has its float
property set, adds highlighted
class to this particular element.
NOTE: this code is not efficient it can be used for your purpose, though, If you want to run it in the console in order to find/debug all the elements that has a float
set on them.
// getting all the children of the `<body>` HTMLElement, but as `node.children` is `HTMLCollection` we need to convert it into an array.
const elems = Array.from(document.body.children);
function highlightElements (elems) {
elems.forEach(function (elem) {
if(elem.nodeType === 1) { // if it is HTML element
if(elem.children.length > 0) highlightElement(Array.from(elem.children));
if (window.getComputedStyle(elem).float !== "none") elem.classList.add("highlighted");
}
});
};
CSS
.highlighted {
outline: 2px solid red;
}
In the example above we find all the elements that have particular class and then add them our own custom class that highlightes them. In our case is the outline
property.