views:

102

answers:

2

i got help (http://stackoverflow.com/questions/1553601/jquery-select-a-tag-with-selector-from-a-text-veriable) 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?

        });
A: 
 var length = 30;
 var end    = '...';
 var div = $('<div>' + text + '</div>');
 $(div).find('a').each(function() {
  var link_value = $(this).html();
  $(this).html(link_value.substring(0, length)+(link_value.length > length ? end : ''));
 });

 var text = div.html();
Basit
+1  A: 

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();
googletorp
hmmm.. i will try later on sometime, to see if it works. but thanks for the response :)
Basit
When you run it through jQ it will convert the HTML to objects, so when you change an attribute on the object it will also take effect for the list of objects.
googletorp