html - Targeting Dynamic ID's in jQuery -
i creating dynamic id inside li element , want target each id can animate opacity. set variable "_btn" console log value of each id returns correct id names when try target id in jquery not animate opacity. doing wrong how target each id in jquery?
var btninfo = [{ img: 'images/thumbs/motiongraphicsthumb1.jpg', id: 'btn1', title: 'title1', url: 'folio/pg1.html' }, { img: 'images/thumbs/motiongraphicsthumb2.jpg', id: 'btn2', title: 'title2', url: 'folio/pg2.html' }, { img: 'images/thumbs/motiongraphicsthumb3.jpg', id: 'btn3', title: 'title3', url: 'folio/pg3.html' }] (var = 0; < btninfo.length; i++) { $('.thumbwrapper .container ul').append('<li class="hidethumbs" id="' + btninfo[i].id + ' " onclick="contentloader(\'' + btninfo[i].url + '\')"><div class="view view-tenth"><img src="' + btninfo[i].img + '"><div class="mask"><h2>' + btninfo[i].title + '</h2></div></div></li>'); var _btn = btninfo[i].id; console.log("btn id " + _btn); $("#" + _btn).animate({ opacity: 100 }); } }
i guess create <li>
s not visible, want use animate()
make them visible smoothly. more hidethumbs
class set display: none;
: way, change opacity
has no effect, , element keeps invisible.
instead css should be:
.hidethumbs { opacity: 0; }
apart above, note that:
opacity: 100
has no sense (though it'll work); values between 0 (invisible) , 1 (fully visible).- you'd better write
var _btn = btninfo[i].id;
before<li>
creation, can usebtn
ratherbtninfo[i].id
inside of it.
Comments
Post a Comment