2009-12-12 5 views
3

나는 많은 div가 있고 나는이 사람을 감추고 싶다.
내가 어떻게 잡은 div의 ID를 얻을 수 있습니까?
"onmouseover"를 사용하여 함수 (및 sendind the id)를 호출하는 것을 제외하고는 어떻게해야합니까?
감사!jQuery : 클래스에서 ID를 가져 오기

답변

14

당신은 당신은 당신이 할 수 있도록 애니메이션을 적용 div의 후 플래그에 클래스를 설정할 수

$('.name').attr('id'); 
0

ATTR 기능을 사용하여 요소의 ID를 얻기 위해

$(".classes").mouseover(function() { 
    $(this).function(); 
}; 

같은 시도 잡힌 div를 쉽게 식별 할 수 있습니다.

(function($){ 
    $.fn.extend({ 
     myDivHover: function(){ 
      var $set = $(this); 
      return $set.each(function(){ 
       var $el = $(this); 
       $el.hover(function(){ 
        fadeOutAnimation($el, $set); 
       }, function(){ 
        fadeInAnimation($el); 
       }); 

      }); 
     } 
    }); 

    function fadeOutAnimation($target, $set){ 

     // Revert any other faded elements 
     fadeInAnimation($set.filter('.hovered')); 

     // Your fade code here 
     ... 
     ... 

     // Flag 
     $target.addClass('hovered'); 
    } 

    function fadeInAnimation($target){ 

     // You revert fade code here 
     ... 
     ... 

     // Unflag 
     $target.removeClass('hovered'); 
    } 

})(jQuery); 

// Apply it to the divs with XXX class 
$('div.XXX').myDivHover(); 

// Select hovered item 
var theID = $('div.XXX').filter('.hovered').attr('id'); 

은 도움이 :) 희망

이 DIV 년대에 호버에
2

...

HTML :

<div class="add_post_cmmnt" id="box-100" >Box1</div> 
<div class="add_post_cmmnt" id="box-200" >Box2</div> 
<div class="add_post_cmmnt" id="box-400" >Box3</div> 

자바 스크립트 :

$(".add_post_cmmnt").hover(function(e) { 

     var id = this.id; // Get the id of this 

     console.log("id is " + id); //Test output on console 

     $('#pid').val(id); // Set this value to any of input text box 

     $(this).fadeOut(400); // Finally Fadeout this div 

}); 
관련 문제