Updating the content of the entire span element with its own text
<div id="resultperpage">
<span><a>12</a></span>
<span><a>24</a></span>
<span><a>48</a></span>
<span><a>98</a></span>
</div>
$('#resultperpage span').click(function() {
$('#resultperpage span').html($(?).html() + 'A'));
});
<div id="resultperpage">
<span><a>12A</a></span>
<span><a>24A</a></span>
<span><a>48A</a></span>
<span><a>98A</a></span>
</div>
Please help me replace question mark in jQuery function to output text + 'A'
+3
source to share
3 answers
You can use the callback function html()
instead to replace everything
$('#resultperpage span').click(function() {
$('#resultperpage span').html(function(_, html) {
return html + 'A';
});
});
or replace only by clicking
$('#resultperpage span').click(function() {
$(this).html(function(_, html) {
return html + 'A';
});
});
+2
source to share