?
Solved

Jquery creating list from array

Posted on 2015-02-19
3
Medium Priority
?
472 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

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 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