If I have this:
<span data-helo="1">something</span>
<span data-helo="2">something different</span>
and I want to target the first span, how should I do it?
I tried something like:
$('span').data('helo', '1')
But it returned both spans.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
try:
this will target all
span-elements with adata-helo-attribute of value1.http://jsfiddle.net/F2NUk/
with your code:
you’re targeting all
span-elements and setting theirdata-heloattribute to1. And then returning that collection (through typical jQuery chaining).