Developer Builds Custom JS Class to Query DOM Elements by Dataset Name and Value
A developer has shared a custom JavaScript class called GetElemsByDataset, designed to collect DOM elements by their dataset name or name-value pairs in a single call. The utility was created as an alternative to standard methods like getElementsByTagName and getElementsByClassName, which the author found limiting in certain workflows. The class accepts four arguments — a parent element, a dataset name, an optional dataset value, and a logging flag — and uses an async constructor with a for-of loop to gather matching elements. It was built as part of a new project started recently, drawing inspiration from the WHATWG specification for built-in HTML DOM methods. The author published the code on DEV Community for others to import and use directly in their own scripts.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in