All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

jQuery Find By Data Attribute Name

Last Updated : Mar 11, 2024

jQuery Find By Data Attribute Name

In this article we will show you the solution of jQuery find by data attribute name, an element on such a web page (or application) can have extra information added to it using the data-* attribute, which can then be utilized for processing.

Every element whose attribute begins with the prefix data- (as word data, followed by such a hyphen) is considered to have a data attribute.

For instance, I have an element that I want to use the ">data attribute to attach some basic data to.

We can just use new element attributes in addition to attributes. This article will show you how to use jQuery to retrieve a value of either a custom attribute inside of an HTML element.

A data attribute is that any attribute on most any element whose attribute name begins with data-. jQuery offers a number of ways to manipulate HTML elements.

To obtain the data-id attribute of such an HTML element, merely employ the jQuery attr() method.

If you utilize jQuery (>= 1.4.3) or a later version,you can attach material of any sort to DOM elements using the.data() method without worrying about memory leaks or circular references.

Step By Step Guide On jQuery Find By Data Attribute Name :-

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
   $(document).ready(function() {
     $('[data-slide="0"]').addClass('demo');
   });
</script>
<style>
.demo {
    font-size: 150%;
    color: red;
}
</style>
</head>
<body>
<p data-slide="0">Ron</p>
<p data-slide="1">Harry</p>
</body>
</html>
  1. The first step is to write <HTML>, which tells the browser what version of HTML we're using. A tag is the first element of an HTML document.
  2. Use the <head> tag to describe the project's heading. In contrast to the final brackets, which are closed, the title and final brackets both are open.
  3. The <script> tag was then added. The script tag also includes the javascript google API run or an explanation of the code or file we used.
  4. The script is then closed.
  5. Then again we open the <script> tag and then add. The script tag also includes the javascript google API run or an explanation of the code or file we used.
  6. The script is then closed.
  7. External style sheets, also known as step-by-step style sheets, appear on a webpage based on the URL or path.
  8. Next, we create the font size and weight in style.
  9. Then The style is then closed and head close.
  10. The <body> tag, which describes the webpage's body, is then placed after this. This is where the website's content is written.
  11. Then we create a data slide
  12. After that we close program using</body></html>

Conclusion :-

The JQuery attr() function allows us to obtain the values of HTML attributes.An attribute can also be set using the same technique.

Moreover, JQuery data() has a function for retrieving HTML5 data attributes that returns the values of all data elements.

I hope this article on jQuery find by data attribute name helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪