I try get a my attribute inside Fancybox, and I get when I use href, but if I try get my attribute I get just “undefined”.
<a class="grouped_elements" rel="Group1" id="@item.Id" private="@item.Private" title="@item.Title" href="/Image/ShowFile/@item.Id">
<img src="/Image/ShowThumb/@item.Id" alt="@item.Title" /></a></div>
function formatTitle(title, currentArray, currentIndex, currentOpts) {
var titlenormal = '<input type="hidden" id="idPhoto" value="' + currentArray[currentIndex].id + '">' +
'<span id="fancybox-title-over">' +
'<div id="boxComment" style="position:relative;"><div style="white-space: nowrap;"><div style="float: left;">' + title + '</div><div id="star" style="width:100%"> </div></div>';
alert($(this).attr("href"));
return titlenormal;
}
if you set the option
titleFormatinside fancybox likethen your function
formatTitleworks and alerts thehrefattribute value.you may also use
this.hrefinsteadEDIT: March 23, 2012 – 12:30pm PT in response to comments.
I guess you were not clear enough to specify which attribute to wanted to get.
Anyways,
alert($(this).attr("href"));works becausehrefis, at this point, a jQuery object inside the fancybox function whileprivateis not.As a workaround, try this instead:
within your
formatTitlefunction like:you could also use the
onCompletecallback instead to get the attributeprivatelike: