I have a list of lines containing text links in a HTML file that I want to transform into hyperlinks and li lists in JavaScript.
Example :
<ul> links links text links </ul>
to
<ul> <li><a href='links'>links</a></li> <li><a href='links'>links</a> text</li> <li><a href='links'>links</a></li> </ul>
This script transforms text links into hyperlinks : http://jsfiddle.net/RH8f6/94
I tried to do the same for adding li tags to each lines:
//Wrap each line with li tags
$('#links').ready(function() {
// Get each ul
$('ul').each(function(){
// Get the content
var str = $(this).html();
// Select each lines starting with url
//trim blank space before and include text after the links)
var regex = /(http.*?).*/ig
// Wrap each new line in textarea with li tags
var replaced_text = str.replace(regex, "<li>$1</li>");
// Echo link
$(this).html(replaced_text);
});
});
... and it doesn't work. I wish to do the multiple replacement preferably in one single JavaScript function.
Thanks a lot in advance!