1

I have a page that loads a fancybox iframe dialog. In that dialog an ajax call can be made that returns a JS response. I want that response in the iFrame to remove an element on the parent window. Here's what I have so far:

$(parent.document + ' #attachment-<%=@attachment.id%>').fadeOut('slow');

This isn't working. Suggestions? thanks

AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
  • possible duplicate of [Run JQuery in the context of another frame](http://stackoverflow.com/questions/539504/run-jquery-in-the-context-of-another-frame) – epascarello Feb 14 '11 at 19:28
  • alert and you will see why it fails `alert(parent.document + ' #attachment-<%=@attachment.id%>');` You are adding an object plus a string so you get something wrong. – epascarello Feb 14 '11 at 19:29
  • ok I tried that as, $('#attachment-<%=@attachment.id%>', window.parent.frames[0].document).fadeOut('slow'); and it doesn't error and has no effect. – AnApprentice Feb 14 '11 at 19:36
  • If I alert I get [object, object] which means jquery can find it. But it doesn't remove or fade out. Is it a problem having jQuery in the parent window and iframe? – AnApprentice Feb 14 '11 at 19:41

1 Answers1

0

In jquery you need a "#" or "." after the "$("

So for example $("#myDiv") or $(".MyDiv"). I'm guessing that is your problem.

RandomWebGuy
  • 1,439
  • 11
  • 23
  • My guess would have been. $('#attachment-<%=@attachment.id%>' Can you confirm that <%=@attachment.id%> is returning something? – RandomWebGuy Feb 14 '11 at 19:47
  • Interesting, so when I click $('body', window.parent.frames[0].document).remove(); in the iframe, it removes the iframes body NOT the parents. – AnApprentice Feb 14 '11 at 19:50