페이지에 일련의 a
태그가 있습니다. 내가 a
의 모든 요소를 통해 iterarte 위해 노력하고 data-followers_count
을 변경하고있어페이지의 각 데이터 속성 업데이트
<a class="follow-user 50126cec60de7d7467000003" data-followers_count="1 Follower" href="#">
Test User
</a>
: 그들은이 같은 모든 같은, 뭔가있다. 오류가 반환되지 않아도 그렇게 할 수 없습니다. http://jsfiddle.net/netwire88/Zrrvq/2/
어떤 아이디어 :
$("body").on("click", ".btn-follow", function(e) {
var el, linkContent;
e.preventDefault();
el = $(this);
user_id = '50126cec60de7d7467000003';
linkContent = $(document).find('.follow-user.' + user_id);
$.each(linkContent, function(index) {
$(this).data('followers_count', 'new count');
//alert('Changed to ' + $(this).data('followers_count'));
});
});
여기 jsFiddle입니까?
코드가 참으로 노력하고 있습니다. Firebug는 변경 내용을 표시하지 않습니다. 루프 안의 값을 변경 한 후에'console.log ($ (this) .data ('followers_count'));를 해보십시오. – techfoobar