-1

i have this jquery code

$("#eioShowLink").on('click',function(){
        $("#ioEditRelatedConcepts").html('');
        $.getJSON("http://localhost/Mar7ba/Ontology/getRelatedConceptsAndRelations/"+conceptName+"/TRUE", function(data){
            var concepts = data[0];
            var relations = data[1];
            for(var i = 0 ; i < concepts.length ; i++){
                (function(currentConcept, currentRelation) {
                    $.getJSON("http://localhost/Mar7ba/InformationObject/getIOsForConcept/"+currentConcept+"/TRUE" , function(data1){
                        var IOS = '';
                        IOS +="<option>Select IO</option>";
                        for(var j=0;j<data1.length;j++){
                            IOS+="<option>"+data1[j]+"</option>";
                        }
                        $("#ioEditRelatedConcepts").append('<p>\n\
              connect to\n\
              <span class="ioAddConcept">'+ currentConcept +'</span>\n\
              with\n\
              <span class="ioAddRelation">'+ currentRelation +'</span>\n\
              <select name ="concetedIOs[]" class="TypeSelector">'+IOS+'</select>\n\
              <span class="errorMessage"></span>\n\
              <a href="#" class="removeA" id="eioRemoveIO">remove</a>\n\
              </p>\n\
              <p>');
                    });
                })(concepts[i], relations[i]);
            }
        });

    });

it works good, now i want when press the link "eioremoveIO" i want to remove the nearlest P tag, so i tried this

$("#editOnePlace").on('click','#eioRemoveIO',function(){
    $(this).closest('p').remove();
});

but nothing happen when pressing, it seems that it doesn't even fired, would you tell me what am i doing wrong?

edit

#editOnePlace" is the id of my div(doesn't appear here)

edit

the html

 <li>
                <p>
                    <label>Concepts</label>
                    <a href="#" class="smallLink" id="eioShowLink">Show Concepts</a>
                </p>
                <div id="ioEditRelatedConcepts">
                </div>
            </li>
4

2 回答 2

3

jQuery 函数最接近给出最近的祖先您可以使用 prev/next 来获取上一个/下一个兄弟。

$("#editOnePlace").on('click','#eioRemoveIO',function(){
    $(this).prev('p').remove();
});
于 2012-07-03T06:19:25.870 回答
2

假设您使用的是最新版本的 jQuery:

 $('#eioRemoveIO').live('click',function(){     
    $(this).closest('p').remove();
 }); 
于 2012-07-03T06:19:42.953 回答