에 ATTR()에 의해 텍스트()를받는 방법 저는 여기에 데이터 g 세트를 가지고있는 ATTR()에 대한 텍스트() 값을하고 싶은 질문JQuery와
<div class="question">
<div class="button" data-q="1" data-a="1"><a href="javascript:void();">2002</a></div>
<div class="button" data-q="1" data-a="2" data-g="true"><a href="javascript:void();">2010</a></div>
<div class="button" data-q="1" data-a="3"><a href="javascript:void();">1985</a></div>
<div class="button" data-q="1" data-a="4"><a href="javascript:void();">2013</a></div>
</div>
입니다.
지금 내가 노력 코드 내가이 일을 시도했습니다
$('.question .button a').click(function(){
var aText = $(this).parents('.question').find('data-g').text();
return aText;
});
작동하지 않습니다하지만 난 .question의 DIV (2002201019852013)
$('.question .button a').click(function(){
var aText = $(this).parents('.question').text();
return aText;
});
내부의 모든 텍스트를 가져
그래서 data-g 속성이있는 DIV의 결과 만 가져 와서 2010 년 텍스트 만 가져올 수 있습니다.
감사
가능한 중복 같이이 값을 다른 함수를 호출해야 데이터 속성 값?] (http://stackoverflow.com/questions/4191386/jquery-how-to-find-an-element-based-on-a-data-attribute-value) 및 [찾는 방법 특정 값을 가진 특정 속성을 가진 요소] (http://stackoverflow.com/questions/9307448/how-to-find-an-element-with-a-specific-attribute-that-has-a-specific- 값) 및 [많은 다른 사람] (http://stackoverflow.com/search?q=jquery+find+element+with+certain+attribute). –