0

I want to open a popup and nest it into a div. I'm using appendTo. my popup has to be open inside the clicked div. parent?

then append some html. what I'm missing?

fiddle: http://jsfiddle.net/XeELs/151/

 if ($("#events .event").hasClass("selected")) {
            $('.popup-event').parent().appendTo($(".event"));
            $(this).fadeIn();
            $('.popup-event').append('<span class="close-popup-event" />'); 
        }else{
            $('.close-popup-event').fadeOut('');
       }

HTML

<div class="event">
</div>



<aside class="popup-event">

</aside>
DD77
  • 1,367
  • 2
  • 13
  • 25

4 Answers4

0

Your first statement is backwards. Either change it to $(".event").appendTo($('.popup-event').parent()); or change appendTo to be append and it will work. Furthermore, verify that both of your jQuery object are not empty.

Cole
  • 119
  • 13
0

You might try something like this:

http://jsfiddle.net/mkprogramming/XeELs/150/

$('.event a').click(function() {
        $('.popup-event').appendTo($(this).parent());
        $('.popup-event').fadeIn();
        $('.popup-event').append('<span class="close-popup-event" />'); 
});​

I think the key part to notice is the $(this).parent()

sirmdawg
  • 2,579
  • 3
  • 21
  • 32
0

I think there are some mistakes in your code. First, I would say it would be better to use id instead of class for popup-event as (as far as I understand) it is unique.

Also, when you write

 $('.popup-event').parent().appendTo($(".event"));

you try to append the parent of your "popup-event" div to your "event" div.

What I would do (If I understand correctly) is this:

$("div.event").bind('click', function() {
 $("#popup-event").appendTo($(this));
});

assuming you've put an id on "popup-event" and you want it to appear inside the clicked div. If you want it to appear inside the parent of the clicked div, you would append to

$(this).parent()
Gaet
  • 699
  • 3
  • 11
0

Check out this fiddle: http://jsfiddle.net/a9AHt/1/

I wrapped the whole thing in <div id="events"> and changed the class to "selected" so the event would fire.

If you take out the .parent() in the appendTo clause then it'll put the right element in.

Also, to make it relative to where that .event div is, you'd want to references $(this) in the click event, so you don't accidentally get another div.

Finally, add position:relative to the .event div to make sure it's always in that element.

tedski
  • 2,271
  • 3
  • 27
  • 48