Guido Anselmi
Guido Anselmi

Reputation: 3912

How to Add an Arbitrary Attribute to an HTML Tag Using AngularJS

I need to dynamically designate some <button>s as having a value like correct=true or correct=false. I see how to use Ideally this attribute would be invisible to the a user clicking 'view source.' I can live with the answer being visible via a JavaScript debugger.

Right now I am storing it in a separate data structure and looking it up via the id which is dynamically constructed by AngularJS:

<div style="padding-top: 5px" class="col-md-offset-3" ng-repeat="answer in answers">
   <button id="answerChoice_{{$index}}" 
           style="font-size: 18px;" 
           class="btn btn-default" 
           ng-click="selectButton($event)" >

           {{answer}}

   </button>
</div>

Upvotes: 1

Views: 1391

Answers (1)

Shipow
Shipow

Reputation: 2447

ng comes with jquery light version so you can script something like

$('button').attr("correct",true);

Upvotes: 2

Related Questions