javascript - Why adding html to textarea gets first img with undefined? -


i have textarea , bunch of images checkboxes replacement, when click on 1 of it, added markup plain text textarea:

html

<textarea name="usp-custom-4" id="usp-custom-4" data-required="false" placeholder="example input 4" data-richtext="false" class="usp-input usp-textarea usp-form-16" rows="5" cols="30"></textarea> 

js

 jquery.each(data.items, function(i, item) {     var uniq = uniqueid('thing_');     var $items = jquery(       '<div class="col-xs-12 col-md-3 grid-item">'.concat(         '<div class="thumbnail">',           '<input type="checkbox" name="', uniq, '" value="valuable" id="', uniq, '" />',           '<label for="', uniq, '">',             '<img class="img-responsive" src="' + item.link + '">',           '</label>',         '</div>',       '</div>')     );     jquery('body').on('change', '.grid .thumbnail :checkbox', function () {       var urls = [];       jquery(':checkbox:checked').each(function () {         urls.push(jquery(this).next('label').find('img').attr('src'));       });       var str = '';       urls.foreach(function (url) {         str += '<div class="carousel-cell"><img class="carousel-cell-image" onerror="this.parentnode.removechild(this);" data-flickity-lazyload="' + url + '"></div>';       });       jquery('#usp-custom-4').val(str);     });  }); 

if select 1 or 2 images, first html coming data attribute undefined value

<div class="carousel-cell">     <img class="carousel-cell-image" onerror="this.parentnode.removechild(this);" data-flickity-lazyload="undefined"> </div> <div class="carousel-cell">     <img class="carousel-cell-image" onerror="this.parentnode.removechild(this);" data-flickity-lazyload="https://profgiovannafraccalvieri.files.wordpress.com/2016/04/impero-romano-2012.jpg?w=812"> </div> <div class="carousel-cell">     <img class="carousel-cell-image" onerror="this.parentnode.removechild(this);" data-flickity-lazyload="http://www.skuola.net/news_foto/2016/divisione-impero-romano.jpg"> </div> 

the bit of code below select checked checkboxes on page, not '.grid .thumbnail :checkbox' possible there checkbox on page not have label , img go it?

 jquery(':checkbox:checked').each(function () { 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -