jQuery: referenciar y manipular el elemento principal de un elemento agregado dinámicamente

I'm loading some XML in my document and add a DIV-button to it. By clicking the button, I wan't to fadeOut() not only the button, but also its parent element. While referencing and fading out the button itself is working, I fail to get access to its parent-element. (see the last lines in my code).


    var searchstring = decodeURIComponent(getUrlVars()["search"]);

        url: 'data.xml',
        type: 'GET',
        dataType: 'xml',
        timeout: 10000,
        error: function(){
            alert('Error loading XML document');
        success: function(xml){
            $(xml).find('entry').filter(function(index) { return $('lemma', this).text() == searchstring; } ).each(function() { 
                $(this).find('part_gp > part').each(function(){
                    var more = $('<div class="more">+</div>');

            $( "#result" ).append( $(this) );


function fader() {
    $(this).fadeOut();   // this works!!
    $(this).parent().fadeOut(); // this doesn't work!!


The XML/HTML will look like this:

  <div class="more">+</div>
  <pos> feminin / weiblich</pos>

I want to hide the whole part_gp..


didn't work either..

preguntado el 02 de febrero de 12 a las 10:02

2 Respuestas

El problema es que estás usando $(this).after(). That is putting your button after the block you want to hide, not inside of it. What you really want is $(this).append().


Respondido 02 Feb 12, 14:02

i dont know how the markup looks like but you can try


Respondido 02 Feb 12, 14:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.