Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise
<ul class="todo-list">
    <li ng-repeat="todo in todos">{{todo.todoContent}}<span class="pull-right glyphicon glyphicon-check" ng-class="{checked:todo.done}" ng-click="todoCheck(todo)" title="check this todo">check</span></li>
  </ul>

Now I want change title attribute to "uncheck this todo" and text "check" to "checked" when I click the span element to check target todo.
Anyone can help here. Thanks very much.

example fiddle

share|improve this question
up vote 2 down vote accepted
<li ng-repeat="todo in todos">
    {{todo.todoContent}}
    <span class="pull-right glyphicon glyphicon-check" 
    ng-class="{checked:todo.done}" ng-click="todoCheck(todo)" 
    title="{{!todo.done && 'check this todo' || 'uncheck this todo'}}">
        {{!todo.done && 'check' || 'checked'}}
    </span>
</li>
share|improve this answer
    
thanks! you help me a lot :) – tjfdfs Sep 13 '13 at 9:07

If you want more fine grained control over the element you clicked, you can do this by using the $event in the ng-click handler.

like

ng-click="todoCheck($event, todo)"

I have used jquery to set the title and content and updated your fiddle.

Here is the updated fiddle

$scope.todoCheck = function ($event, todo) {

   var spanElement = $event.srcElement;

   $(spanElement).attr('title', "uncheck this todo");

   $(spanElement).html("checked");

   todo.done = !todo.done;

};

share|improve this answer
    
thanks too. another way to get this done. and yes, I may need to get element directly someday. :) – tjfdfs Sep 13 '13 at 9:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.