vodkabears / Remodal

No longer actively maintained.
http://vodkabears.github.io/remodal/
MIT License
2.75k stars 771 forks source link

Access Other Attributes From <a> Inside Event #180

Closed marcopolo8 closed 8 years ago

marcopolo8 commented 9 years ago

Quick question, I'm using the "opened" event handler to perform some jQuery updates as well as make an Ajax call. I wanted to know how can I access the value of the "href" attribute that calls Remodal? For example:

Link:

<a data-remodal-target="myDivName" href="122">View Info</a>

Event:

$(document).on('opened', '.remodal', function () {
//I want to access the value of the href attribute of the clicked link above inside this handler
//var href = $(this).attr('href');
});

Thanks for any tips.

zacol commented 9 years ago

Maybe don't use opened event? If you use ajax to load modal content, I think that waiting for opened event is little too late. I do that this way:

find('.modal-open').click(function(event) {
    event.preventDefault();
    var link = $(this);
    var url = link.data('ajax-route') || link.attr('href');

    $.ajax({
        url: url,
        data: null,
        dataType: 'html',
        success: function(response) {
            $('.remodal').append(response);
            var modal = $('[data-remodal-id="modal"]').remodal({
                hashTracking: false
            });
            modal.open();
        }
    });
});

I hope that this will help you :)

marcopolo8 commented 9 years ago

@zacol I really appreciate it man! This is a HUGE help! Again, thanks for offering help.