Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i got help (Select a Tag with a Selector from a Text Variable using jQuery) on looping the static var and replacing it value, but just one question is left from it, is how can i replace finded tags with newly changed tags in the text area

Code:

var length = 30;
var end    = '...';
var text = `some string here with <a href="#link">http:something.com</a> more string and more links also`;

$('<div>' + text + '</div>').find('a').each(function() {

                var link_value = $(this).html();
        $(this).html(link_value.substring(0, length-1)+(link_value.length > length ? end : ''));
// now how can i put $(this).html() back in the text area, which it was found at?

        });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

Actually when changing this one way or the other, the changes are made and you don't need to put it back instead just use end()

var div = $('<div>' + text + '</div>').find('a').each(function() {...}).end();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...