views:

66

answers:

1

I have the following lines of code:

    $("a.quickview").fancybox({
        ajax : {
            type    : "POST",
            data    : 'itemID=' + $(this).attr("name")
        }
    });

Which is binding on:

<a name="614" class="quickview" href="/URL/index.cfm">quick view</a>

I want data to post as itemID=614, but $(this).attr("name") is coming back as undefined? What am I doing wrong?

Thanks

A: 

The way you wrote it $(this) is not what you expect. this in this context isn't the a clicked on but whatever this is when you run $("a.quickview").fancybox({...}).

Use this code instead

$("a.quickview").each(function() {
    var a = $(this);
    a.fancybox({
        ajax : {
            type    : "POST",
            data    : 'itemID=' + a.attr("name");
        }
    });
});

or if there is only one a.quickview you want to bind fancybox to use this simpler code

var a = $("a.quickview");
a.fancybox({
    ajax : {
        type    : "POST",
        data    : 'itemID=' + a.attr("name");
    }
});
jitter
there is a list of quickview's <ul>.... I just tried the code it no matter which quickview I click, it always is finding the name ATTR for the first A in the list <LI>, and not the one I clicked on... Ideas?
AnApprentice
What do you mean by list of quickview's `<ul>`? Your selector says `a.quickview` which means all `<a>` tag that have the class quickview
jitter