is it possible to create a identification attribute sort of a class or an id and assign it in jQuery selector with special character?
for example I want an “identity” attribute to be recognized as @ (or any other special character)
same like an “id” attribute recognized as #
sort of
<div identity="myDiv"></div>
and Jquery
$("@myDiv").click(...);
Thanks!
Sure, use the the
attribute-equals-selector[docs].Note that this needs to look at every element on the page and check for the attribute.
You’ll gain some performance if you select by class, or add a class to a group of elements, and narrow those down by your custom attribute.
Or if all the potential elements are located in a container with an ID, then definitely narrow your selection down to descendants of that element.
or
EDIT:
You can define custom filters in jQuery if you wish:
This simply uses the native
getAttributeto get theidentityattribute, and compare it to the value passed. If you need different processing, you can add it to the filter function.The same rules apply about narrowing the selection for performance.