0

i have a jquery each loop binded images with ids like : $("[id^=MokeImage]"). actually i want to hover,to enlarge the images .i think there is some problem in the ids which i am not finding please help me out.

$(document).ready(function () {
        $("[id^=MokeImage]").hover(function () {
            $(this).addClass('transition');

            }, function () {
                $(this).removeClass('transition');
            });
        });
        
        
.transition {
  -webkit-transform: scale(1.6);
  -moz-transform: scale(1.6);
  -o-transform: scale(1.6);
  transform: scale(1.6);
}

img[id^=MokeImage] {
  -webkit-transition: all .4s ease-in-out;
  -moz-transition: all .4s ease-in-out;
  -o-transition: all .4s ease-in-out;
  -ms-transition: all .4s ease-in-out;
}

img[id^=MokeImage] {
  width: 50px;
  margin: 50px;
}

This is the Binding of images using ajax :

 $(document).ready(function () {
     
            $.ajax({
    
                type: "get",
                url: "@Url.Content("~/Sales/GetGangingTransportOrders")",
                data: ({ CustomerId: selectedcutomer }),
    
                datatype: "json",
                traditional: true,
                success: function (data) {
    
                    var json = data.GangingBatchModel;
                    
                    **$.each(json, function (index, obj) {
                        var row =
                               '<tr><td style="width:20mm"><img src="' + 
          obj.ImageUrl + '" id = "MokeImage' + index + '" style="width:100%"/></td></tr>'**  
                              
                    });
    });
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
  • Try delegating the event with http://api.jquery.com/on/ and use for example the **body** as reference. – DaniP Feb 19 '18 at 16:39
  • Get rid of the `id` attribute and just use a class name instead. And as noted above, when you dynamically add items to the DOM, you need to use [event delegation](https://learn.jquery.com/events/event-delegation/) –  Feb 19 '18 at 22:37
  • Possible duplicate of [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) –  Feb 19 '18 at 22:38
  • @Stephen..Thanks,using class it worked – sumit.spider Feb 20 '18 at 08:12

0 Answers0