Welcome Guest, Not a member yet? Register   Sign In
[solved] jquery removing parent
#1

[eluser]SPeed_FANat1c[/eluser]
After image deletion from server I want to remove the span with this this picture, delete link and radio button. Span looks like this:

Code:
<span class="article_img">
<img src="http://localhost/darzelis/uploads/naujienos/naujiena.jpg">
&lt;input type="radio" name="image"  value="http://localhost/darzelis/uploads/naujienos/naujiena.jpg"&gt;
<a class="trinti_img" href="" id="naujiena.jpg"><img src="http://localhost/darzelis/images/admin/delete.png"></a>
</span>


Code:
$('a.trinti_img').live('click',function(){
        
        name = this.id;
        
         jConfirm('Ar tikrai norite ištrinti?', 'Patvirtinimas', function(r) {
             if(r){
                
                
                 $.post(CI.base_url + 'admin_/naujienos/delete_picture_ajax/'+name,{filename: name},  function(data) {
                    
                     if(data != 'not_admin') //this is true
                         $(this).parent().remove();
                         //console.log('test');
                    
                    });
             } //if r
         });
         return false;
     });

So the span is parent if I understand well. Where is my mistake?
#2

[eluser]Madmartigan1[/eluser]
Try $(this).parents('span').remove()

For some reason, I've had no luck with parent()

You might get more help in a Jquery forum.
#3

[eluser]cideveloper[/eluser]
What's with all the javascript questions in the codeigniter forums?

$(this) inside a .post returns the jquery post object not the object clicked. Do a console log on $(this) and you will see

Code:
$('a.trinti_img').live('click',function(e){
    e.preventDefault();
    $.post("test.php", {filename: name}, function(data){
        console.log(data.response);
        //$(this).parent().remove();
        console.log($(this));
    });

});

you need to get the element before you post.

Code:
$('a.trinti_img').live('click',function(){
        
        name = this.id;
        var elem_clicked = $(this);
        
         jConfirm('Ar tikrai norite ištrinti?', 'Patvirtinimas', function(r) {
             if(r){
                
                
                 $.post(CI.base_url + 'admin_/naujienos/delete_picture_ajax/'+name,{filename: name},  function(data) {
                    
                     if(data != 'not_admin') //this is true
                         elem_clicked.parent().remove();
                         //console.log('test');
                    
                    });
             } //if r
         });
         return false;
     });
#4

[eluser]SPeed_FANat1c[/eluser]
[quote author="progr@mmer" date="1293679460"]What's with all the javascript questions in the codeigniter forums?

$(this) inside a .post returns the jquery post object not the object clicked. Do a console log on $(this) and you will see


[/quote]

Thank you, I didn't think that post returns some object so I though I can ignore it Smile

And for the javascript question there - I see I am not only one who posts them, I guess its ok. And it is very confortable to ask it here, not go in some other forum. It would be more nice if there would be javascript forum section imo.




Theme © iAndrew 2016 - Forum software by © MyBB