views:

439

answers:

1

Sorry for all the dumb jquery questions I'm still learning and find this to be a GREAT resource!

How can I show a <li> on click of a class here is my html

<li><a href="#" rel="sample.gif">sample.gif</a> <a href="#" class="edit_project_file"> <img src="images/edit.gif"/></a></li>    
<li class="edit_project_image" style="display:none;"><input name="upload_project_images[]" type="file" /></li>');

I am trying this (and many other combination) for my jquery:

$('.edit_project_file').click(function() {
$(".edit_project_file").next("li.edit_project_image").show();
return false;

I originally thought i would need to use this but if I understand "this" correctly it gets the current element so then i thought i needed to get the next element after the current li.

As always, Any help would be great!

Edit: here the php code actually being used,

         $image_project_images_q = mysql_query("SELECT i_project_id,i_name,i_type FROM `project_images` WHERE `i_project_id` = '$project_data[p_id]' AND i_type = '2'");
    while($image_project_image_data = mysql_fetch_array($image_project_images_q)){
 echo ('<li><a href="#" rel="'.$upload_project_images_path.$image_project_image_data['i_name'].'">'. $image_project_image_data['i_name'].'</a> <a href="#" class="edit_project_file"> <img src="images/edit.gif"/></a></li>');
      echo('<li class="edit_project_image"><input name="upload_project_images[]" type="file" /></li>');
      }

Final Edit:

Because the code is being generated though a php while loop the jquery needed to be

$('.edit_project_file').live('click',function() {
$(this).parent().next().show();
return false;

});

+1  A: 
$('.edit_project_file').click(function() {
    $(this).parent().next().show();
    return false;
});

Assuming your markup will be as consistent as your example, this should work. Just remember you have to descend upwards because you are in an anchor that is a child of the li, then the next sibling is the li that you want to show.

Live example: http://jsbin.com/edovu

FYI: I think you have an unclosed li tag.

meder
For some reason that didn't work, do I need to define the value of either parent() or next()? Sorry, I'm new to this.
BandonRandon
Why do you have a `')` at the end of your code? Are you dynamically updating and inserting html? If so you'll need to use .live('click', fn )
meder
Oh, you have malformed markup. You didn't close the first li.
meder
yes, the `<li>` are being generated by a php while loop pulling the image names out of a database. So, because of that I need to do it a different way?
BandonRandon
Can you please verify the html that you have is correct and valid?
meder
It should be valid, thanks for the live example, i added the php while loop above. Sorry for making this more difficult.
BandonRandon
Ok, THANK YOU THANK YOU THANK YOU! I got it to work by using the .live as you suggested the code I used is.$('.edit_project_file').live('click',function() { $(this).parent().next().show(); return false;});
BandonRandon