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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -