0
     function listContents(storagename) {

        alert("inside function");
        //Clear up the list first
            $('#results').html("");
            var files = navigator.getDeviceStorage(storagename);

            var cursor = files.enumerate();

            cursor.onsuccess = function () {
              //alert("Got something");
              var file = this.result;
              if (file != null) {
        var imageElement = $('<img height="100" width="75">');
              imageElement.attr('src', window.URL.createObjectURL(file));
              var tagvalue=  $("<p>" + file.name + "," + file.lastModifiedDate + "," + file.type + "," + file.size  + "</p>").appendTo('#results');
              imageElement.appendTo("#results");
                this.done = false;
              }
              else {
                this.done = true;
              }

              if (!this.done) {
                this.continue();
              }
            }
}

imageElement.onclick = function() { 
console.log('onclick function!');
//alert('blah');
}

I am retrieving audio file list from SDCard in Firefox OS. Now I want to upload this file to server so for that when I do onclick on image element I am able to do any event so I am trying to display alert box but it is not working.

Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73

1 Answers1

0

In your sniplet imageElement is not visible outside listContents function, you need to register onclick handler in other way, by binding.

$('#results > img').on('click', function() { 
  console.log('onclick function!');
  //alert('blah');
});

Or register it inside inside listContents function.

Secondly if you are using jQuery, stick to it, use click(), on() methods, instead plain javascript events (onclick in your example)

As a tip: to clean element content use empty function, like so:

$('#results').empty();
Beri
  • 11,470
  • 4
  • 35
  • 57
  • http://stackoverflow.com/questions/29767442/button-event-is-not-working-in-fire-fox-os hey i have made some changes like instead of image element i am creating button but still it is not working.not showing alert box.here link is there.plz hepl me to resolve this issue – user3679542 Apr 21 '15 at 08:57
  • @user3679542 If you have moved this question, please close/resolve this one, we would like to keep stact as clean as possible :) – Beri Apr 21 '15 at 09:02