0

The code, loads some 'divs' and pops them all in a single dialog object (Sec1).

Each alert has a "dismiss" link(Sec2), with a JQuery event-listener that sends an ajax request, and shows a new dialog, created from the result (Sec3).

Seems like it's all working, but, with one problem: after clicking the 'dissmis', the result dialog is loaded in many (10, currently, in a previous version of the code, only 5..)

 //Sec1
 $("#alerts_list").dialog({
    title : "Alerts",
    resizable : false,
    dialogClass : "alerts",
    modal : true,
    maxHeight: $(window).height()- 20,
    buttons : [{
       text : "Done",
       click : function() {
          $(this).dialog("close");
       }
    }]
 });

The alerts code is:

HTML

//Sec2
<div class="alert<?php echo " " .$alert_class?>">
   <h3>Title</h3>
   <p class="alert-message">some text</p>
   <div class="toolbar">
      <a class="dismiss" href="/alerts/dismiss/1">dismiss</a>
      <a href="/alerts/">settings</a>
   </div>
</div>

//Sec3
$(".alert .toolbar a.dismiss").on('click',function(eve) {
   eve.preventDefault();
   $url = $(this).attr("href");
   $.get($url, null, function(data) {
      $("p").html(data).appendTo('body').dialog();
   });
});
1
  • How many <p> elements do you have in your page? $("p") selects all of them. Commented Jan 15, 2014 at 8:08

2 Answers 2

1

You probably want to replace $("p") with $("<p></p>") or $("<p>").

Sign up to request clarification or add additional context in comments.

1 Comment

You are absolutely correct! i used $("P") instead of $("<P>"). thanks!
1

This selector:

$("p").html(data).appendTo('body').dialog();

is affecting all your <p> elements.

Try to use a more specific selector.

Code:

//Sec3
$(".alert .toolbar a.dismiss").on('click',function(eve) {
   eve.preventDefault();
   $url = $(this).attr("href");
   $.get($url, null, function(data) {
      $(this).parent().siblings("p").html(data).appendTo('body').dialog();
   });
});

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.