Home > Web Front-end > JS Tutorial > How Can I Retrieve a Data-id Attribute from a Clicked Item Using jQuery's Quicksand Plugin?

How Can I Retrieve a Data-id Attribute from a Clicked Item Using jQuery's Quicksand Plugin?

Patricia Arquette
Release: 2024-12-31 09:55:09
Original
256 people have browsed it

How Can I Retrieve a Data-id Attribute from a Clicked Item Using jQuery's Quicksand Plugin?

Retrieving the data-id attribute

Question:

When utilizing jQuery's Quicksand plugin, how can I access the data-id attribute of a clicked item and pass it to another web service? Specifically, how do I retrieve the data-id value using the .on() method for dynamically bound click events on sorted elements?

Answer:

To obtain the data-id attribute value, you can employ the following approaches:

  1. Using attr():
alert($(this).attr("data-id"));
Copy after login
  1. Using data() (for jQuery >= 1.4.3):
alert($(this).data("id"));
Copy after login

Note:

  • Data attributes should use lowercase names, for example, data-idnum instead of data-idNum.
  • For the .attr() method, the attribute name should be enclosed in double quotes, while for .data(), it should not.

The above is the detailed content of How Can I Retrieve a Data-id Attribute from a Clicked Item Using jQuery's Quicksand Plugin?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template