Reputation: 179
I'd like to insert the character entity ✓ (✓
) at the end of a list item after an href has been clicked:
<a href="" id="answer1">Click here to answer</a>
<ul>
<li>Answer 1</li>
</ul>
$("#answer1").click(function(){
// Add ✓ to the end of the list item, such as: "<li>Answer 1 ✓</li>"
});
Any help is much appreciated! Thanks!
Upvotes: 2
Views: 930
Reputation: 28755
I don't know how much li elements you have, but for this html as you shown
$("#answer1").click(function(){
$('ul li').append('✓');
});
Upvotes: 0
Reputation: 4330
You can use the following code
$("#answer1").click(function(){
$(this).html() += $(this).html() + '✓'; // just format the Html anyway you want
});
Edit
I mis-read your question.
for your UL ie... its something like
<ul>
<li>Answer 1</li>
<li>Answer 2</li>
<li>Answer 3</li>
</ul>
then your Html to show the answers - perhaps store the answers index:
<a href="" class="anwers" data-answer="0">Click here to answer</a>
in your javascript
$("a.answers").click(function(){
// get the answer index
var i = $(this).attr("data-answer");
var answer = $("ul > li:eq(" + i + ")");
answer.html( answer.html() + '✓' );
});
Upvotes: 1