javascript - Close link not working and opening modal window instead -


i have 'a' tag, when clicked, removes thumbnail gallery calling jquery click event. if dynamically add thumbnail image , remove on same page without refreshing, click event doesn't triggered. triggers modal window pop (as if clicking on image). if press 'x' (to close) modal window triggers jquery click event remove image. works fine on non dynamically added thumbs or if page has been refreshed.

$('a.close').click(function () {            var imageid = $(this).attr('id');      $.post(              '/managespaces/removeimage',              { id: imageid }          );      $(this).parents('li').remove();  });
<div id="row">    <ul id="sortable">      @foreach (var image in model.images.orderby(i => i.ordering)) {      <li id="@image.yogaspaceimageid" class="col-sm-6 col-md-4 imagethumbs" data-yogaspaceid="@model.yogaspaceid">          <div class="thumbnail">          <a id="@image.yogaspaceimageid" class="close" href="#">×</a>          @{ var base64 = convert.tobase64string(image.imagethumbnail); var thumbsrc = string.format("data:image/gif;base64,{0}", base64); var base64modal = convert.tobase64string(image.image); var imgsrcmodal = string.format("data:image/gif;base64,{0}", base64modal);          var imageid = "pop" + image.yogaspaceimageid; var imagesourceid = "imagesource" + image.yogaspaceimageid; }          <a class="image" id="@imageid" href="" data-toggle="modal" data-target="#mymodal">            <img id="@imagesourceid" src="@thumbsrc" data-imagesrc="@imgsrcmodal" alt="image not found" width="203" height="136" />          </a>          <div class="caption">            <h3>thumbnail label</h3>            <p>...</p>            <p><a href="#" class="btn btn-primary" role="button">button</a>  <a href="#" class="btn btn-default" role="button">button</a>            </p>          </div>        </div>        </li>      }    </ul>    <div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">      <div class="modal-dialog">        <div class="modal-content">          <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span>          </button>          <a href="" data-toggle="modal" data-target="#mymodal">            <img id="modalpreview" alt="image not found" width="355" height="355" />          </a>        </div>      </div>    </div>  </div>

this snippet of js adds new thumbnail when user selects new image , appends ul list.

var listitem =           "<li id=\"" + responsetext.yogaspaceimageid + "\" class=\"col-sm-6 col-md-4 imagethumbs\" data-yogaspaceid=" + $("#hiddenyogaspaceid").val() + ">" +              "<div class=\"thumbnail\">" +              "<a id=\"" + responsetext.yogaspaceimageid + "\" class=\"close\" href=\"#\">×</a>" +                  "<a class=\"image\" id=\"" + imageid + "\" href=\"\" data-toggle=\"modal\" data-target=\"#mymodal\">" +                      "<img id=\"" + imagesourceid + "\" src=\"" + thumbsrc + "\" data-imagesrc=\"" + imgsrcmodal + "\" alt=\"image not found\" width=\"203\" height=\"136\" />" +                  "</a>" +                  "<div class=\"caption\">" +                      "<h3>thumbnail label</h3>" +                      "<p>...</p>" +                      "<p><a href=\"#\" class=\"btn btn-primary\" role=\"button\">button</a> <a href=\"#\" class=\"btn btn-default\" role=\"button\">button</a></p>" +                  "</div>" +              "</div>" +          "</li>";        var $li = $(listitem);      $('ul#sortable').append($li);

$('a.close') selects available elements, if add new element need call jquery on well.

$(element).youroriginalquery 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -