hellomello
hellomello

Reputation: 8597

Rails: closing a custom modal window after opening through ajax

I'm having trouble closing the modal window... I can't even test an alert if I'm click within the modal window:

$ ->
  $('#Close').on "click", ->
    alert("testing")

This is the content within the modal window

#Root
  #Bg
  #Main
    #Info
    #MainControls
      #Close{style: "cursor:pointer;"}
        %a.CloseButton
          %i X

My modal window is being rendered through this:

$('body').append('<%= j render partial: "trips/quick_view" %>');

In one of my views:

= link_to trip.id, quick_view_trips_path, remote: true

So the partial is being rendered, when someone clicks on the quick_view_trips_path. How do I close this window?

Upvotes: 0

Views: 494

Answers (1)

Jaehyun Shin
Jaehyun Shin

Reputation: 1602

Click event on #Close is not binded. Because when $('#Close').on "click", -> code is running, there is no #Close div.

You should bind event like this,

$('body').on 'click', '#Close', ->

Upvotes: 1

Related Questions