Reputation: 2626
I have a number of values that are being passed via the URL, that I need to capture in an array, to replace text elements on a page. For example:
URL: http://www.domain.com/?client=ClientName&project=ProjectName
I'm looking to have a simple piece of html which will have the values inserted. For example
<ul>
<li>Client: <span class="client"></span></li>
<li>Project: <span class="project"></span></li>
</ul>
This should produce:
It is possible that the pieces of data will need to be written a number of times on a page, hence the use of the span tags with classes.
Can anyone advise as to how this can be achieved using jQuery. Thank you in advance for any suggestions.
Upvotes: 0
Views: 1504
Reputation: 2782
I think you need something like that: http://jsfiddle.net/8WTA6/2/
var params = window.location.search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var param = params[i].split('=');
$("." + param[0]).html(param[1]);
}
Upvotes: 1