开发者

Replace value in unordered list (html) + JQuery

开发者 https://www.devze.com 2023-01-11 20:50 出处:网络
D1 D2 D3 I need to change just the values between开发者_StackOverflow <span>and </span> D1, D2, D3 with JQuery, with new values like X1,X2,X3 with JQuery.$(\'#nav-d1 span\').text(\'X1\'
D1 D2 D3

I need to change just the values between开发者_StackOverflow <span> and </span> D1, D2, D3 with JQuery, with new values like X1,X2,X3 with JQuery.


$('#nav-d1 span').text('X1') would change <span>D1</span> to <span>X1</span>


use

$('#navigation').find('span').each(function(){
    var $this = $(this);
    $this.text(function(i, curr){
         return curr.replace(/D/, 'X');
    });
});

That would fit exactly your example.

0

精彩评论

暂无评论...
验证码 换一张
取 消