Finding element(s) by data attribute = variable using jQuery
Finding element(s) by data attribute = variable using jQuery
18331-Jul-2023
Updated on 01-Aug-2023
Home / DeveloperSection / Forums / Finding element(s) by data attribute = variable using jQuery
Finding element(s) by data attribute = variable using jQuery
Aryan Kumar
01-Aug-2023Sure, here is how to find elements by data attribute = variable using jQuery:
JavaScript
The
elements
variable will contain an array of all the elements with the data-attribute of "variable". Theeach()
method will loop through the elements and execute the function for each element.Here is an example of how to use this code:
HTML
This code will create two div elements, one with the data-attribute of "variable" and one with the data-attribute of "other-variable". The
each()
method will loop through the elements and print the element to the console.