1

I want to know how I can get the value of data-id from my div:

<div class="customer-row selected-row" data-id="83BA1B29-15B9-4B11-BA47-DEB453362426"><strong>Mario Rossi</strong></div>

I tried with:

$('#customer-row .selected-row').data('id');

but return undefined, why?

2
  • Shouldn't it be $('.customer-row .selected-row').data('id'). You have got #customer-row there in the jquery statement which resolves to nothing. Commented Jan 2, 2016 at 18:06
  • One question. Why are you using <strong>? Commented Jan 2, 2016 at 18:15

2 Answers 2

2

Because your selector is wrong, you selector tries to find an element with class selected-row inside the element with id customer-row, instead you should be selecting an element which has both the class, I hope you know that # is for ID and . is for class. So just do:

$('.customer-row.selected-row').data('id');
Sign up to request clarification or add additional context in comments.

Comments

1

Your selector is not correct. customer-row is class not id and also remove the space between .customer-row and .selected-row. Try like following.

$('.customer-row.selected-row').data('id');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.