0

I'm using jquery dialog popup. I have multiple div's (dynamically created) that require the pop-up on a single page. My current issue is when I click the .open, all (10) pop-ups are opening, how can I trigger only one?

My html is as follows:

      <a class="open" href="#">
          <img src="/images/someImage1.jpg" />
      </a>

    <div class="dialog" title="Gives Dialog Title"><!-- This is display:none in css-->
    <p> Dialog text and stuff</p>
   </div>

   <a class="open" href="#">
          <img src="/images/someImage1.jpg" />
      </a>

    <div class="dialog" title="Gives Dialog Title"><!-- This is display:none in css-->
    <p> Dialog text and stuff</p>
   </div>

My jquery is as follows:

   <script type="text/javascript"> // added .dialog:disaplay:none; to desktop.css


  $(document).ready(function () {

      $('a.open').prop('id', function (i) {
          return '' + (i + 1);
      });

      $(".dialog").dialog({
              autoOpen: false,
              draggable: false,
              width: "300px",
              modal: true,
              buttons: {
                  "Close": function () {
                      $(this).dialog('destroy').remove()
                  }
              }

          });

      $("#1,#2,#3,#4,#5,#6,#7,#8,#9,#10")

   .click(function () {
  alert($(this).attr("id"));

  $(".dialog").dialog("open");
  return false;
   });
  });

    </script>

3 Answers 3

2

This should work (or a variant of it).

$("#1,#2,#3,#4,#5,#6,#7,#8,#9,#10").click(function () {
  alert($(this).attr("id"));

  $(this).next(".dialog").dialog("open");
  return false;
});
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried this, but for some reason it makes it that there are no pop-ups.
Just to be sure, you're not replacing all of your code with this, right?
0

I feel the need to tell you to just use a class as your click handler

$(".open").click(function(e) {
    e.preventDefault();
    $(this).next(".dialog").dialog("open");
});

There's no need for the ID's if you're not using them.

Comments

0

If I am reading your code correctly what you are doing is

$('.dialog').dialog('open');

i.e. you are getting hold of all elements that use the dialog class. Naturally, that opens all your dialogs all at once. If you rewrite your markup along the lines

<div class="dialog" title="Gives Dialog Title" id='diaOne'><!-- This is display:none in css-->
  <p> Dialog text and stuff</p>
</div>

and then do

$('#diaOne').dialog('open');//grab just the dialog bearing the id diaOne.

that should I suspect do the trick

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.