2
<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

2 Answers 2

4

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;

};

Sign up to request clarification or add additional context in comments.

1 Comment

thanks too. another way to get this done. and yes, I may need to get element directly someday. :)
2
<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.