JQuery.on () method is not tied to all elements of Phonegap application on Android 4.0

I have the following code. This seems to be fine, since all the elements of the image can be clicked on all ios and newer Android devices, but only those elements that are visible on the screen when the page loads can be clicked on Android 4.0.

 $('a.openMediaDetails').on('click', function() {

Here is the code in context.

var HTML = [];
            var jsonParse = JSON.parse(evt.target.result);
            $.each(jsonParse.MediaList, function(mediaDataIndex, mediaDataVal) {
                HTML.push('<div class="item1"> <a data-transition="slide" data-mediaurl="', mediaDataVal.BigImageUrl, '" data-caption="',mediaDataVal.Caption,'" class="openMediaDetails"><img src="data:image/jpeg;base64,', mediaDataVal.ThumbBase64String, '" class="image" alt=""/></a> </div>');
            });
            $('#media-list1').html(HTML.join(''));
            //$('#media-list .item:last, #media-list .item:nth-last-child(2)').addClass('disBorderBottom');

            HTML.length = 0;

            $('a.openMediaDetails').on('click', function() {
                var networkState = navigator.connection.type;
                var states = {};
                states[Connection.NONE] = false;
                if(states[networkState]===false){
                    alert('No network connection');
                    $('.openMediaDetails').removeAttr('href');
                }else{
                    $('.openMediaDetails').attr('href', '#imageDetails');
                    $('#imageDetails #mediaDetailsImage').attr('src', $(this).data('mediaurl'));
                    $('#imageDetails .download').attr('href', $(this).data('mediaurl'));
                    $('#imageDetails #image_caption').html($(this).data('caption'));
                }
            });
+4
source share
3 answers

, , , . Chrome Cordova , Android 4.4. Googled around Crosswalk https://crosswalk-project.org/, - Chromium Android 4.4. . , , Crosswalk. Chrome . . , Android, jQuery.on() .

+1

.on()

 $(document).on('click','a.openMediaDetails', function() {

-.on()

+1

DOM, , , ,

$(document).on('click', 'a.openMediaDetails', function() {
  // you code here
});

, , . ,

 $('.parent').on('click', 'a.openMediaDetails', function() {
  // you code here
 });
+1

Source: https://habr.com/ru/post/1621425/


All Articles