How do I remove the first character from a link's text with jQuery?

前端 未结 4 1527
星月不相逢
星月不相逢 2021-01-04 03:46

I want to remove first character from link\'s text with jQuery.

 +123.23 
 -13.23 

        
相关标签:
4条回答
  • 2021-01-04 03:51
    $("span.test1, span.test2").each(function() {
      $(this).text($(this).text().replace(/[+-]/, ""));
    });
    
    0 讨论(0)
  • 2021-01-04 03:53
    // get the current text
    text1 = $(".test1").html();
    // set the text to the substring starting at the third character
    $(".test1").html(text1.substring(2)); // extract to the end of the string
    
    text2 = $(".test2").html();
    $(".test2").html(" " + text2.substring(2)); // looks like you want to keep the leading space
    
    0 讨论(0)
  • 2021-01-04 04:06
    var val = $("span").html();
    $("span").html(val.substring(1, val.length));
    
    0 讨论(0)
  • 2021-01-04 04:12

    you can get/set the HTML using .html() and remove the first character using .substring(), I think it's pretty clear now, you just need to write a 2 (or 3) lines code.

    0 讨论(0)
提交回复
热议问题