Created
June 4, 2012 22:28
-
-
Save jephjohnson/2871197 to your computer and use it in GitHub Desktop.
Get the words from a string in multiple divs using a for loop with jQuery or regular expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$("#d0, #d1, #d2").each(function() { | |
var text = $(this).text(); | |
var textArr = text.split("*"); | |
$(this).html("<ul></ul>"); | |
for(var i = 0; i < textArr.length; i++) { | |
$(this).find("ul").append('<li><a>' + textArr[i] + '</a></li>'); | |
}; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.textTolist = function() { | |
var textArr = $(this).text().split('*'), | |
target = $(this).empty().append('<ul></ul>'); | |
for (var i = 0; i < textArr.length; i++) { | |
$('ul', target).append('<li><a>' + textArr[i] + '</a></li>'); | |
} | |
}; | |
})(jQuery); | |
$('#d0, #d1, #d2').each(function() { | |
$(this).textTolist(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment