javascript - Convert [object Object] into DOM element -
i trying implement slideshow in jquery have images , description in hidden element id contain
here want of containing elements (img
span
) pairs can iterate them. issue is:
var slides = $('#contain').children(); //[object object] console.log(slides); //console.log(slides.get(0)); //< not working
this returning [object object]
want element in dom elements can select details, iterate them etc.
can please how can that?
complete code:
function startslideshow(interval) { var slides = $('#contain').children(); console.log("0: " + slides); (var = 0; < slides.length; i++) { settimeout( function () { var slide = $(slides[i]).children(); $('#currentimage').attr('src', slide[0].src).fadein(interval * 100); $('#slidedesc').html(slide[1].innerhtml).fadein(interval * 100); }, interval * 1000); } }
in html:
<article id="contain"> <div class="image"> <img src="http://i.imgur.com/925p6m5.jpg" /> <span>1lorem ipsum dummy text of printing , typesetting industry. </span> </div> <div class="image"> <img src="http://i.imgur.com/dbbu5rk.jpg" /> <span>2 lorem ipsum dummy text of printing , typesetting industry. </span> </div> <div class="image"> <img src="http://i.imgur.com/vfxpgei.gif" /> <span>3 lorem ipsum dummy text of printing , typesetting industry. </span> </div> </article>
problem is throwing me errors like: uncaught typeerror: cannot read property 'src' of undefined
you may try this
var slides = $('#contain').children().get(); console.log(slides); // array of dom elements console.log(slides[0]); // first dom element
or
$('#contain').children().each(function(k, v){ console.log(v); });
Comments
Post a Comment