Checks if the target has the ID property that matches id.
target
id
Note that you can pass an ID string or CSS selector (e.g. #some-id). If your ID starts with # and is not a CSS selector, ensure there are two # prefixes instead of one.
#some-id
#
Element, EventTarget, or CSS selector.
ID to check for element.
true if the target has the specified id.
true
InvalidElementError if the specified target wasn't found.
InvalidElementError
HTML
<div class="example" id="no-hash">Example</div><div class="example" id="#hash">Example</div> Copy
<div class="example" id="no-hash">Example</div><div class="example" id="#hash">Example</div>
Code
const [noHash, hasHash] = findAllElements(".example");idMatches(noHash, "no-hash");// trueidMatches(hasHash, "#hash");// falseidMatches(hasHash, "##hash");// true Copy
const [noHash, hasHash] = findAllElements(".example");idMatches(noHash, "no-hash");// trueidMatches(hasHash, "#hash");// falseidMatches(hasHash, "##hash");// true
Checks if the
target
has the ID property that matchesid
.Note that you can pass an ID string or CSS selector (e.g.
#some-id
). If your ID starts with#
and is not a CSS selector, ensure there are two#
prefixes instead of one.