简体   繁体   中英

jquery opening a link with a class

I am using a third party payment system that opens up a small popup that allows the user to enter their details.

I can see that they are using fancybox but cannot edit their js or css.

I have a current setup that uses jquery that creates steps that guide the user through the various payment options and platforms i use.

At the moment the other payment platforms being used open a new page. I want this one platform to open the fancybox. I am able to link to it with jquery (it switches the link based on the amount).

My issue is that I need to inlude a class thats normally in the tags, using location.href I cant seem to keep this class which opens the overlay rather than a new window.

so currently:

r += (r.indexOf('?') > -1 ? '&' : '?') + 'amount=' + $('#plus_amount').val()
location.href = r;

Opens as new page

What i need:

<a class="payment-widget" href="payment link">

Is there any way to open a link with jquery and have it use a class as well?

Thanks in advance

Nad

I'm not sure what you mean by "open a link using a class", but you can open fancybox manually instead of using location.href :

$.fancybox.open({
    href : r,
    title : 'Title'
},{
    //options
});

Demo: http://jsfiddle.net/HK29L/

Or if you want to assign the href to the anchor:

$('.payment-widget').attr('href', r);

(and then you can trigger a click if you like).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM