2012-05-30 2 views
2

가능한 중복 :
JQuery, is there a way to select all elements on the page with a specific attribute?선택 요소에만

내 코드

<html> 
    <body> 
     <script> 
      $(function(){ 
       $("No idea what to write here").remove(); 
      }); 
     </script> 

     <button data-fun="a">Remove</button> 
     <div data-fun="b">Remoave</div> 
     <span data-fun="c">Remdove</span> 
     <strong data-fun="d">Rdemove</strong> 
     <b data-fun="e">Remosve</b> 
     <p data-fun="f">Remoe</p> 
     <div>Not Remove</div> 
    </body> 
</html> 

내가 상관없이 data-fun 속성이없는 모든 요소를 ​​제거 할 것 요소는이고 값은 data-fun입니다.

+0

방법에 의한 화려한 질문 +1 : P 마음에 드는 비트는'$ ("여기에 쓸 내용이 없습니다")':) –

+2

[jQuery 설명서] (http://api.jquery.com/), 특히 [선택자] (http://api.jquery.com/category/selectors/)와 관련하여 –

답변

4

이 작업을 시도 할 수 있습니다 :

$(function() { 
    $("[data-fun]").remove(); 
}) 

Working sample

+1

@Webtecher 데모를 확인하십시오 – thecodeparadox

+1

@Webtecher 제 대답에 대한 문제를 설명해 주시겠습니까? 내 명료성 때문이야. – thecodeparadox

+0

정답으로 처음으로 응답 한 사람은 +1입니다. – arttronics

관련 문제