Delete Last Char of String with Javascript

前端 未结 9 894
独厮守ぢ
独厮守ぢ 2021-02-07 05:57

I have a DIV with some characters. How can I remove the last character from the text with each click on the DIV itself?

9条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 06:01

    If you wanted to delete the first character of the text every click you could use substring. e.g.:

    $("#textDiv").click(function(){
      $(this).html($(this).text().substring(1));
    });
    

提交回复
热议问题