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?

Abel D
  • 1,040
  • 1
  • 18
  • 30

3 Answers3

1

Use .filter with the attribute selector:

foo.filter('[data-bar="baz"]')
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

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

$('.modal-dialog[data-modal]').show();
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53
0

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

$('.modal-dialog[data-modal="student"]').show();
Inspector Squirrel
  • 2,548
  • 2
  • 27
  • 38