Question

I try to remove one box i append in jQuery, but i can't get it removet after i add, sombody can tell me what i dit worng?

    function appendBox( id )
    {
        $("#listContainer").append("<div id=\"appendbox["+ id +"]\"><a href=\"javascript:removeBox("+ id +");\">remove</a></div>");
    }
    function removeBox( id )
    {
        $("#appendbox["+ id +"]").slideUp();
    }
Was it helpful?

Solution

function appendBox( id )
{
    $("#listContainer").append("<div id=\"appendbox-"+ id +"\"><a href=\"javascript:removeBox("+ id +");\">remove</a></div>");
}
function removeBox( id )
{
    $("#appendbox-"+ id ).slideUp();
}

#appendbox[something] does not mean "the element of id appendbox[something]" but a lot of different things depending on something.

OTHER TIPS

For a fully working script you need to wrap the parameter to removeBox in single quotes because it wants a string: javascript:removeBox('"+ id +"'); otherwise it tries to send a variable which doesn't exist.

function appendBox( id )
{
    $("#listContainer").append("<div id=\"appendbox-"+ id +"\"><a href=\"javascript:removeBox('"+ id +"');\">remove</a></div>");
}

function removeBox( id )
{
    $("#appendbox-"+ id ).slideUp();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top