2014-04-08 2 views
1

두 개의 div가 있습니다. 하나는 버튼이고 다른 하나는 텍스트 상자입니다. 버튼을 클릭하고 텍스트 상자를 트리거하여 그 자체를 드러내고 싶습니다. 그냥 jquery 알아낼 필요가있어. 나는 그것이 단순하다는 것을 알고 있지만, 그것은 나에게 새로운 것이다. 지금까지는 이것이 내 마크 업입니다.JQuery 클래스에 클릭 이벤트 추가 + 이벤트 핸들러의 CSS 변경

HTML

<div class="title"> 
Piece 1 
    </div> 

<div class="description"> 
This is my text. 
    </div> 

CSS

.title.clicked { background-color:#991B1E; } 
.description { display:none; } 

JS

$(document).ready(function() { 
    $(this).on('click', function() { 
     $(this).addClass('title'); 
    }); 
}); 

답변

0

div.description 경우 즉시 F ollows div.title, 그냥 next()를 사용

$(document).ready(function() { 
    $('div.title').on('click', function() { 
     $(this).addClass('clicked') 
       .next('.description').show(); 
    }); 
}); 

Demo합니다.

관련 문제