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 开发者_StackOverflow社区
<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;
});
$('.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.
精彩评论