Extract word from string using jquery or javascript
I would like to extract word from tag like
<li>{firstname} {last name}</li>
开发者_JAVA百科So, can I get extract strings "firstname" and "last name" using javascipt or jquery?
Actually I think I have made some mistake to explain.
my String looks like
<li><a href="#contactDetail">{firstname} {lastname}</a></li>
here i would like to know how many parameters available means {first..} {last...} that can be only {fi..} and I would like replace with some other parameters.
So, I have a list of array which includes many parameters like firstname, lastname, address and so on... now I would like to replace that with according to what i will get from string.
Hopefully, I have tried my best to explain my problem.
if the li element is part of the dom use something like:
var names = $('body ul li').text().split(' ');
var firstName = names[0];
var lastName = names[1];
You could try something like this.
http://jsfiddle.net/W5Uh6/2/
Markup
<ol id="names">
<li>Jason Brown</li>
<li>Danny Glover</li>
<li>Jack Jill</li>
</ol>
JS
$(function(){
var firstNames = [];
var lastNames = [];
$("#names li").each(function(){
var text = $(this).text().split(' ');
firstNames.push(text[0]);
lastNames.push(text[1]);
});
});
Puts each word into an array that is separated by a space. You an then grab the values from the array.
精彩评论