Steven Mouret
Steven Mouret

Reputation: 5940

Accessibility : Set focus upon closing Fancybox 2

I'm trying to make Fancybox 2 accessible, but I can not set focus on the opening link when Fancybox is closed.

I tried this function but it does not work:

beforeClose: function() {
    $(".fancybox").eq(this.index).focus();
}

Upvotes: 0

Views: 1061

Answers (1)

JFK
JFK

Reputation: 41143

You just said to yourself "... when Fancybox is closed " so use the afterClose callback instead like :

afterClose: function() {
    $(this.element).focus();
}

See DEMO (easier to perceive in Chrome)

$(this.element) refers to $(this) in fancybox ... the link from where you invoked fancybox.

Upvotes: 1

Related Questions