Delete Last Char of String with Javascript

前端 未结 9 724
独厮守ぢ
独厮守ぢ 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:09

    To supplemnt on Jonathons answer, use..

    $("div.myDiv").click(function(){
      $(this).html( $(this).text().replace("/.$/gi", "o") );
    });
    

    To remove the last character

提交回复
热议问题