2014-09-10 3 views
-2

나는이 HTML을 가지고 있습니다. 내가 이런 식으로다른 섹션에있는 버튼을 제거하는 방법

var locationname = 'SoftSol'; 
$("#restmenu").find('section').not("#"+locationname).find('.addNewRestaurant').remove(); 

그러나 그 버튼을 제거하지 시도

<div id="restmenu" class="restMenu"> 
    <ul> 

     <section id="LocationX" class="ulseWrap lielement"> 
     <div class="intit">LocationX<span class="inDelete"></span></div> 
     <ul class="restListings"> 
      <div class="inner-intit"> 
       <sub class="sub">Your Favorite Restaurant</sub><br> 
       <li> 
        <h6>Swaghat</h6> 
        <p>MadhaPur , Near Policstation,Hyderabad</p> 
        <span class="inDelete inDeleteSub"></span> 
       </li> 
      </div> 
      <input type="button" location="LocationX" name="btn1" class="btn btn-success addNewRestaurant" value="LocationX"> 
     </ul> 
     </section> 

     <section id="SoftSol" class="ulseWrap lielement"> 
     <div class="intit">SoftSol<span class="inDelete"></span></div> 
     <ul class="restListings"><input type="button" location="LocationX" name="btn1" class="btn btn-success addNewRestaurant" value="LocationX"></ul> 
     </section> 

    </ul> 
</div> 

나는 SoftSol 위치에 버튼 선물을 제거해야합니다.

누구든지 내게 무슨 문제인지 알려 주실 수 있습니까?

난 여전히 문제가 있습니다 것은, 내가

이것은 SoftSol의 버튼 선물을 제거하려면 내 코드

function showRestaurantDetailsByLocation(responseeee,locationname) 
{ 

     var ulhtml = $('<ul class="restListings"></ul>'); 
     var divhtml = $('<div class="inner-intit"><sub class="sub">Your Favorite Restaurant</sub></div>'); 
     divhtml.append('<br>'); 
     for(var i=0;i<responseeee.length;i++) 
     { 
      divhtml.append('<li><h6>'+responseeee[i].name+'</h6><p>'+responseeee[i].address+'</p><span class="inDelete inDeleteSub"></span></li>'); 
     } 
     ulhtml.append(divhtml); 
     $('.restListings').empty(); 
      $("#"+locationname).append(ulhtml); 
      $("#restmenu").not("#"+locationname).find('.addNewRestaurant').remove(); 
var $newbutton= $('<input/>').attr({ type: 'button', location:locationname , name:'btn1', class:'btn btn-success addNewRestaurant',value:locationname}); 
     $('.restListings').append($newbutton); 
     $(".restListings").show(); 
     $("#restmenu").show(); 
} 
+2

가 작동하는 것 같군 dom이로드되기 전에이 코드를 실행하십시오. – smerny

+0

당신도 SoftSol에서 버튼을 제거하길 원한다는 언급을 보았지만, Softsol에서 버튼을 제외한 모든 것을 제거하려고하는 것처럼 보입니다. SoftSol에서 버튼을 제거하려면, 왜 단지'$ ("# "+ locationname) .find (". addNewRestaurant "). remove();'? – smerny

+0

올바르게 작동하고 있습니다. 다른 문제가 있습니다. – afzalex

답변

0

이름 addNewRestaurant과 다른 부분에 존재하는 버튼을 제거 할 수 없습니다 수 위치 수행 :

$("#restmenu").find("#"+locationname).find('.addNewRestaurant').remove(); 

현재는 not("#"+locationname)을 사용하고 있으므로 삭제됩니다. 다른 버튼을 클릭하면 요소가 아닌 restmenu 요소 내에있는 addNewRestaurant 클래스의 다른 모든 버튼이 제거됩니다. http://jsfiddle.net/rp7w40sL/, 아마도 당신이 jQuery를로드하지 않았거나 당신이 -

JS Fiddle Demo

+0

아직 문제가 있습니다. 코드를 업데이트했습니다. 문제를 알려주십시오. – Pawan

0

var locationname = 'SoftSol'; 
$("#restmenu").find("#"+locationname).find('.addNewRestaurant').remove(); 

작업 시도는 Demo

+0

두 단추를 모두 제거합니다. – Dan

+0

@ Dan, 감사합니다. 아 .. 내 잘못 .. 지금 고쳐 줬어. –

관련 문제