1

In a website, I'm using jquery tools.

In a lot of places, I've to do the same action:

When I click on a link, I display a popup:

This is done easily by

$(".overlayTrigger[rel]").overlay({
    mask: {
        color: '#111',
        loadSpeed: 300,
        opacity: 0.9
    },

        closeOnClick: true
    }
);

But the problem is that I would like, in each case, call a javascript method which loads some data for my popup.

I know there is a parameter of the trigger that I can set:

onLoad: function() {
   //Call the method specified in data-load-method attribute
},

And my goal is to call my custom method in the onLoad: function(){} and the method has to be specified on the <a href> through something like an attribute:

<a href="#" class="overlayTrigger" rel="#MyPopupDiv" data-load-method="LoadPopupXYZData">Click here for the popup</a>

Is there any way to do that?

2
  • You are already using data-attributes. If your a has an attribute of data-key="hello" you can use $(this).data('key') to get the "hello". See: api.jquery.com/data - Or am I missing something? Commented Apr 13, 2012 at 8:17
  • where is this method defined? Commented Apr 13, 2012 at 8:22

3 Answers 3

3

If i understand you correctly, you want to do something like this:

onLoad: function() {
   var method = $(this).data('load-method');
   window[method]();
},

If not, please clarify.

Sign up to request clarification or add additional context in comments.

3 Comments

attr() returns a string, not a function.
instead of eval: window[method]()
hamczu, just found that out. :) +1
1
<a href="#" class="overlayTrigger" rel="#MyPopupDiv" onclick="LoadPopupXYZData()">Click here for the popup</a>

Comments

0

use click or hover methos like this

$(".overlayTrigger[rel]").click(function(){
//inside this method u can access the element using
//$(this) and execute the overlay showing
//also u can accesss the element and its attributes using $(this)
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.