Adding bullets to Jquery - Jquery closest -
i have following code:
$('.add-bullet').click(function() { $(this).closest('textarea').val( $(this).closest('textarea').val() + '\u2022' ); return false; }); <div><a href = "#" class = "add-bullet">add bullet</a></div> <textarea name =""></textarea>
for reason, when click on add bullet, not adding textarea, meaning closest not working. can do?
likely scoping problem "this".
you want pass onclick event in function, like
$('.add-bullet').click(function(e) { $(e.target).closest('textarea').val( $(e.target).closest('textarea').val() + '\u2022' ); return false; });
try that.
Comments
Post a Comment