jQuery trick: get elements by any attribute

In jQuery coding we are used to get elements by id or class name.

<br />
<p>jQuery(&quot;.element_class_name&quot;)....<br />

But it is also possible to get elements by any attribute name.

For example lets get element which name is ‘element_name’

<br />
jQuery('[name=&quot;s&quot;]')....<br />

Or by any custom non-standard attribute.

<br />
jQuery('[data-image=&quot;any_image_src&quot;]')....<br />

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: