jQuery trick: get elements by any attribute

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

jQuery("#element_id")....

jQuery(".element_class_name")....

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

For example lets get element which name is ‘element_name’

jQuery('[name="s"]')....

Or by any custom non-standard attribute.

jQuery('[data-image="any_image_src"]')....

Leave a Reply

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