0

I have a php script that fetches the results into lists, but the list come out with the sublists in the bottom of the ul, this script isnt mine but im trying to sort the sublist into their right place.

results are like this now:

<ul id='list'>
<li class='47'>DVD</li>
<li class='48'>Spill</li>
<li class='49'>Utstyr</li>
  <ul class='sublist 49' style='display:none;'>
  <li>Dvd spillere</li>
  <li>Dvd/Blueray spillere</li>
  </ul>
 <ul class='sublist 47' style='display:none;'>
  <li>Barnefilmer</li>
  <li>Voksen filmer</li>
  </ul>
</ul>

But all with sublist 47 should be under li class 47.

Is there any way to have jquery sort out this?

teecee
  • 485
  • 5
  • 10
  • 2
    You really should fix the PHP. – sje397 Dec 13 '10 at 14:11
  • And numbers are not valid CSS class names. See here: http://stackoverflow.com/questions/448981/what-characters-are-valid-in-css-class-names – sje397 Dec 13 '10 at 14:12
  • you can retrieve the html of sublist 47 and then give that html to li class 47......i am just tellimg a way...may be another option work well. – Vivek Dec 13 '10 at 14:13
  • @sje397 +1. I'll add that jQuery **is no magic**. Since your html isn't relevant, don't try to fix with jQuery! jQuery isn't a tool to repair **errors** so don't use it to that purpose. Fix the original error! That said, jQuery can be used to _toggle_ or whatever animation you want to do with those hidden `ul`. – Shikiryu Dec 13 '10 at 14:15
  • Yeah your right, i should try to fix the sqlquery to sort it right. – teecee Dec 14 '10 at 16:28

1 Answers1

0

I don't know how much this will help, considering that your class names aren't valid, but it's quite easy to 'reparent' an element in jQuery:

$('parent-selector').append($('child-selector'));

...so assuming you can select the sublists and their proper parents properly, this should be all you need.

sje397
  • 41,293
  • 8
  • 87
  • 103