2016-09-07 3 views
0
을 제거 클래스 이름을 찾기 나는 일반적인 클래스 이름으로 사업부에서 모든 ID를 제거하기 위해 노력하고

안녕 :다음 ID 번호

$('div.panel-group').removeAttr('id', ''); 

하지만 작동하지 않습니다. 나는 (예를 들어 ID가 다음 ID를 제거 찾을 수)하지 않는 한이의 스택 생성 된 ID의

+1

단 1 매개 변수를 사용하여 시도 :'.removeAttr ('ID')를'| https://api.jquery.com/removeAttr/ – kosmos

+3

$ ('div.panel-group'). removeAttr ('id');'설정하는 매개 변수가 두 개있는 경우 – guradio

+0

불행히도이 방법은 작동하지 않습니다. 나는 성공적으로 $ ('# myID123')을 할 수있다. removeAttr ('id'); 클래스 이름을 검색하고 싶습니다. – roshambo

답변

0

이 하나가 나를 위해 일한 들으, 나는 요소의 ID와 경고를 표시하고 난의 ID를 삭제 그 다음 요소가 표시되면 경고가 다시 표시되면 ID가 정의되지 않습니다.

<div class="panel-group" id="test"> 
First Div 
</div> 
<div class="panel-group" id="test2"> 
Second Div 
</div> 

스크립트 :

$('div.panel-group').each(function(){ 
      alert($(this).attr('id')); 
     $(this).removeAttr('id'); 
     alert($(this).attr('id')); 
}); 

는 또한 Jsfiddle을 확인은 : https://jsfiddle.net/f72q9wao/ 어쨌든

, 그래서 우리는 더 나은 아이디어를 수있는 HTML을 공유하려고합니다.

+0

Thx,하지만 작동하지 않습니다. – roshambo

0

시도해보십시오. 이것은 당신이 원하는 것을 설명 할 것입니다. 첫 번째 div를 클릭하십시오. 클래스 이름이 발견 된 이름과 같으면 div.then의 ID가 제거되어 해당 스타일의 모든 스타일이 제거됩니다. 이것이 당신에게 도움이되기를 바랍니다.

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title></title> 
 
\t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
\t 
 
</head> 
 

 
<style type="text/css"> 
 
div.container div{ 
 
\t width: 100px; 
 
\t height: 100px; 
 
\t border:1px solid black; 
 
\t margin:20px; 
 
\t cursor: pointer; 
 

 
} 
 

 
.first{ 
 
\t background-color: orange; 
 
} 
 

 
.second{ 
 
\t background-color: pink; 
 
} 
 

 
.third{ 
 
\t background-color: purple; 
 
} 
 

 
#firstid{ 
 
\t border:10px solid red; 
 
} 
 

 
</style> 
 

 
<body> 
 
\t 
 
<div class="container"> 
 
\t <div class="first" id="firstid">class = "first" and <br> id="firstid"</div> 
 
\t <div class="first" id="secondid">class = "first" and <br>id="secondid"</div> 
 
\t <div class="second" id="thirdid">class = "second" and <br>id="thirdid"</div> 
 
\t <div class="third" id="fourthid">class = "third" and <br>id="fourthid"</div> 
 
</div> 
 

 

 
</body> 
 

 
<script type="text/javascript"> 
 
$(document).ready(function() 
 
{ 
 
    \t $("div.container div").click(function(){ 
 
    \t \t var the_class = $(this).attr('class');//get the class name of clicked one 
 
    \t \t var the_id = $(this).attr('id');//get the id of the clicked 
 

 
    \t \t alert("The class name :" +the_class + " and the id :"+the_id); 
 

 
    \t \t //then implment your condition 
 
    \t \t if (the_class == "first") 
 
    \t \t { 
 
    \t \t \t $("[class='first']").removeAttr('id'); 
 
    \t \t } 
 

 

 

 
    \t }); 
 
    \t 
 
}); 
 

 

 
</script> 
 
</html>