2012-07-27 3 views
0

페이지에 일련의 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입니까?

+0

코드가 참으로 노력하고 있습니다. Firebug는 변경 내용을 표시하지 않습니다. 루프 안의 값을 변경 한 후에'console.log ($ (this) .data ('followers_count'));를 해보십시오. – techfoobar

답변

0

는 바이올린 업데이트

$("body").on("click", ".btn-follow", function(e) { 
    var el, linkContent, popoverContent, urlString, user_id; 
    e.preventDefault(); 
    el = $(this); 
    user_id = '50126cec60de7d7467000003'; 
    $('.follow-user.' + user_id).each(function(index) { 
     $(this).data('followers_count', 'new count'); 
     alert($(this).data('followers_count')); //confirms changed 
    }); 
});​ 

을 시도해보십시오 예상대로 http://jsfiddle.net/Zrrvq/7/

+0

흠 ... 나는 실패했다. 나는 Gon을 시도하는 것을 끝내었다. – Dean

+0

하지만 피들 나는 일을했습니다. – Utkanos

+0

코드에 다른 충돌이있을 수 있습니까? 하지만 Knockout/Backbone을 작동시키지 못했습니다. – Dean