Selecting element by data attribute with jQuery?
Selecting element by data attribute with jQuery?
Student
I am Utpal Vishwas from Uttar Pradesh. Have completed my B. Tech. course from MNNIT campus Prayagraj in 2022. I have good knowledge of computer networking.
Sure, here is how to select an element by data attribute with jQuery:
JavaScript
The
elementvariable will contain a reference to the element with the data-name attribute of "my-name".Here is an example of how to use this code:
HTML
This code will create two div elements, one with the data-name attribute of "my-name" and one with the data-name attribute of "other-name". The
console.log()method will print the element with the data-name attribute of "my-name" to the console.