How to add a specific class to appended LI which is loaded via ajax?
<p>This is my code. What I am trying to do is add a class "featured" to the first li item which gets added to this UL however, when I try this code, it does not work, it always add the class to every li inserted, while I want the class to be added only if there are no li in the ul and to the first li element added to this UL.</p>

<p>My code:</p>

<pre><code>$(".img_add").click(function(event){
    event.preventDefault();
    $('input:submit, p.upload-result').hide(); // hide submit button + results while working
    $(this).parent().after('&lt;p class="loading"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/img/loading_2.gif" alt="" /&gt;&lt;/p&gt;');
    var path_img = $("#img_url").val();
    var count_images_lib = $(".upload-images-lib").length;
    $.ajax({
        url: '&lt;?php bloginfo('template_directory'); ?&gt;/ajax/add_image_url.php',
        type: 'POST',
        data: { path : path_img },
        dataType: 'json',
        success: function(data){
            $('.loading').remove();
            $('input:submit').show();
            if (data.status) {
                $('.upload-images-lib').prepend(data.message);
                if (count_images_lib == 1) {
                    $('.upload-images-lib li:first-child').addClass('featured');
                }
                alert(count_images_lib);
                $('p.upload-result').fadeIn(500).html('&lt;span class="success"&gt;&lt;?php _e('Your image has been added successfully.','sofa'); ?&gt;&lt;/span&gt;');
            } else {
                $('p.upload-result').fadeIn(500).html('&lt;span class="error"&gt;' + data.message + '&lt;/span&gt;');
            }
        }
    });
});
</code></pre>

<p>What I want is to add the class to the first loaded li only. <strong>Please note: data.message is actually a list item in html format.</strong></p>

<p>The problem is with count_images_lib always returning 1 and thus my class is added everytime. It is not with first/last selector.</p>
