0

I have a jsfiddle here - http://jsfiddle.net/Q73Nd/3/

and demo here - http://www.ttmt.org.uk/forum/thumb/

I want to sequentially load the thumbnails and then load a bigger image of the first thumbnail above.

My problem is I can't get the href for the large image from the <a>

I have vars to the <a> and a imgCounter. I'm trying to use these to get the href

    console.log(link[imgCounter]).attr('href');

How do I get the href here?

4

2 回答 2

5

link is a jQuery object, link[imgCounter] is a DOM element.

Either use .eq [docs] to get the element as jQuery object

// jQuery object
link.eq(imgCounter).attr('href') // or .prop('href)

or access the DOM element's href property

// DOM element
link[imgCounter].href
于 2013-05-04T12:40:31.620 回答
1

您应该在控制台上收到此错误

Object [object HTMLAnchorElement] has no method 'attr'

你需要做这样的事情

console.log($(link[imgCounter]).attr('href'));

http://jsfiddle.net/mohammadAdil/Q73Nd/6/

于 2013-05-04T12:41:29.570 回答