I have reviewed How can I change the text inside my <span> with jQuery? to get where I am. However, that does not cover dynamically created buttons.
I am creating buttons dynamically which contain a label.
$("<button type='button' id='" + this.patExeId
+ "' name='exerciseMachine' class='btn exeBtn btn-large col-lg-2 col-md-2 col-sm-2 col-3 m-1 p-3' "
+ "value='" + this.exeName + "'>" + this.exeName + " <span class='label label-light label-as-badge'>0</span></button>").appendTo($("#allExercises"));
The three "this.patExeId" values are
- OA==
- Mg==
- Mw==
I want to update the label as exercise sets are completed. I am using this test code that is triggered when the button is clicked:
$('#'+$(this).attr('id')+ ' span').html('3');
This is triggering an error shown in the console log:
jquery.min.js:2 Uncaught Error: Syntax error, unrecognized expression: #OA== span