-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting clicked element's attributes #135
Comments
Hi @jelewis8, One way to do this is like so: var my_link = $('.my-link');
my_link.modaal({
before_open: function() {
my_link.data('foo');
// or
my_link.attr('href');
},
after_open: function() {
my_link.data('bar');
}
})``` |
This only works for individual instances.
If you have multiple instances ('.clickthis'), this only picks up the first
instance on the page.
Of course, this is fine if you're using IDs but it's not so great if you
don't have that option.
…On Sun, Nov 15, 2020 at 7:36 PM danodm ***@***.***> wrote:
Hi @jelewis8 <https://github.com/jelewis8>,
One way to do this is like so:
var my_link = $('.my-link');
my_link.modaal({
before_open: function() {
my_link.data('foo');
// or
my_link.attr('href');
},
after_open: function() {
my_link.data('bar');
}})```
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCTOXIPICH6XFGUPKII3LSQBXYFANCNFSM4TU7VUBA>
.
--
-Jeremiah
|
@jelewis8 Correct. There are a number of ways you could approach this similarly to fetch those attributes. I don't believe this is an issue with Modaal at all, but something for you to establish in the rest of your javascript. |
@danodm that makes sense, but I sure wish you were in the mood to show an example of a solution. : ). Will share whatever I come up with... once I've solved it. |
@jelewis8 Here's what I have come up with
What I'm doing is binding the clicked object to the modaal function, using jQuery's on method. |
Ohhhh, that is clever--and I've never seen it done in this way before (I'm
not a JS wiz so maybe this is common).
I'm going to give that a try.
…On Tue, Nov 17, 2020 at 10:20 AM Mike iLL Kilmer ***@***.***> wrote:
@jelewis8 <https://github.com/jelewis8> Here's what I have come up with
$('.info-popup').on('click', function() {
var unique_id = $(this).data('unique_id');
return $(this).modaal({
after_open: function(ev){
console.log(unique_id);
},
start_open: true
});
});
What I'm doing is bind
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind>ing
the clicked object to the modaal function, using jQuery's on
<https://api.jquery.com/on/> method.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCTOTD2OE5XDAZSTN2DRDSQKICFANCNFSM4TU7VUBA>
.
--
-Jeremiah
|
@jelewis8 I think the cleverness is on behalf of the creators of Javascript (and, I guess jQuery). I think this is actually a really common (unless it's wrong) way of doing it, and you and I are just ignorant (but becoming less so.) |
That is fair! Still, it's amazing when you see it, it feels so obvious, but
it would not (was not) obvious before seeing it. Happy to always be
learning new techniques.
…On Tue, Nov 17, 2020 at 10:26 AM Mike iLL Kilmer ***@***.***> wrote:
@jelewis8 <https://github.com/jelewis8> I think the cleverness is on
behalf of the creators of Javascript (and, I guess jQuery). I think this is
actually a really common (unless it's wrong) way of doing it, and you and I
are just ignorant (but becoming less so.)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCTOWXZFWV6DSCBND36CTSQKI2PANCNFSM4TU7VUBA>
.
--
-Jeremiah
|
I've fixed it like this:
|
Is there a way to pull the clicked element's attributes (such as custom data attributes, or the href, for instance) into the modaal ?
I've tried $(this) inside before_open but it returns null.
The text was updated successfully, but these errors were encountered: