javascript - Cannot call method 'find' of undefined -
i'm trying use objects within jquery code.
i've this:
var opts = { ul: $(this).find('.carousel'), li: ul.find('li') }
li
property gives error cannot call method 'find' of undefined
how can fixed?
it doesn't matter selector is, can't access property of object declaring, while declaring it.
why ul
declared? you're making property ul
on opts
object.
ugly:
what might want is:
var opts = { ul: $(this).find('.carousel') } opts.li = opts.ul.find('li');
but if don't need references both groups then:
cleaner:
var opts = { li: $(this).find('.carousel li') }
is good.
cleanest:
you do:
var $carousel = $(this).find('.carousel'); var options = { carousel: $carousel, carouselitems: $carousel.find('li') }
godawful, asked it:
var carouseloptions = (function () { var options = function (carousel) { this.carousel = $(carousel); this.carouselitems = this.carousel.find('li'); }; options.prototype.myoptionsfunction = function () { // don't know want object do, wanted prototype... }; return options; })(); var opts = new carouseloptions($(this).find('.carousel'));
also
(be careful this
is, presumably have more 1 .carousel
element on page, , here want 1 within target of event.)
Comments
Post a Comment