Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jquery creating list from array

Posted on 2015-02-19
3
Medium Priority
?
540 Views
Last Modified: 2015-02-19
Hello experts.
I'm stucking with my list i want to create from one array.
The problem is as follow
Usig the following code:
var cList = $('#catlist');
var catValues = new Array();
$('#myholder').find('li.ui-selected').each(function() {
   catValues.push($(this).text());
});
$.each(catValues, function(i) {
 var li_a = $('<li/>').appendTo(cList);
 var span = $('<span/>').addClass('test').text(catValues[i]).appendTo(li_a);
})

Open in new window

i get the output like:
<ul id="catlist">
 <li>
 <span class="test">my text</span>
</li>
</ul>

The result i need is:
<ul id="catlist">
 <li>
 <span class="test"></span>my text
</li>
</ul>

(the text after the span)
Any help please??
0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 40620256
Hi,
here we go:
    var cList = $('#catlist');
    var catValues = new Array();
    $('#myholder').find('li.ui-selected').each(function() {
       catValues.push($(this).text());
    });
    catValues.push('Test One');
    catValues.push('Test Two');
    catValues.push('Test Three');
    catValues.push('Test Four');
    $.each(catValues, function(i) {
         var li_a = $('<li/>').appendTo(cList);
         var span = $('<span/>').addClass('test').appendTo(li_a);
         li_a.append(catValues[i]);
    });

Open in new window


Sample:
http://jsfiddle.net/EE_RainerJ/28fgr4rd/

HTH
Rainer
0
 
LVL 2

Author Comment

by:Panos
ID: 40620267
Thank you Rainer Jeschor
Sometimes the solution is in front of me and i don't see it.
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 40620268
regards
panos
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question