0

I have many divs with class .modal-dialog and a data field like data-modal='student' and set it to display:none

I select and store it on variable like

    modal_dialog= $('.modal-dialog')

Now I need to show modal with a particular data-modal attribute.

I tried

modal_dialog.hasData('student').show();
modal_dialog.data('student').show();

but didn't work. Any idea how to get this work?

3
  • Please use the search before you ask a new question. Commented Jul 28, 2015 at 16:33
  • Those does not have selection variables. I am not dumb to post question right away. Commented Jul 28, 2015 at 16:37
  • 1
    Ah now, I see. Use .filter then: api.jquery.com/filter. Commented Jul 28, 2015 at 16:37

3 Answers 3

1

Use .filter with the attribute selector:

foo.filter('[data-bar="baz"]')
Sign up to request clarification or add additional context in comments.

Comments

0

If the data field is an actual attribute, you can do

$('.modal-dialog[data-modal]').show();

Comments

0

If you need to look for the actual value in data-modal,

$('.modal-dialog[data-modal="student"]').show();

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.