I am new to Javascript / JQuery and PHP and I am experimenting with it. Basically, I created a simple image gallery in which each picture has an opacity of .4 until you click on it and it becomes 100% opaque. Now I took another step and used PHP to scan the catalog of images and add them to the list of images in the gallery. The current code looks like this:
$(document).ready(function(){ var i = 0; var names; function returndata(files){ names = files; for(i=0; i < names.length ; i++){ $('<li id="img_' + i + '"><img src="../Gallery_pictures/' + names[i] + '"/></li>').appendTo('#thumbnails ul'); } } $.post('../php/read_directory.php',function(data){ var files = $.parseJSON(data); returndata(files); }); });
The code works and adds the images to the list on the web page, but how can I add a jQuery add to the newly created images? I have searched all over the place for an answer to this, but maybe I will just skip the answers. This and the image disappear in separate external Javascript files. Thanks in advance.
* EDIT: * Good, so I got it to work with your suggestions, but now the problem is that the script does not run until the image is first blurred. All images start with full opacity until they are hidden, and then they all become opaque. 4. Any way to fix this? I will also try if I can easily do this in css.
* DOUBLE EDIT: * Therefore, I can easily do this with css, and it works the way I want. Thanks for all the answers.
source share