2

I have also created a jsfiddle to demonstrate my problem.

I need to have the time before the title.

<ul> 
<li>
    <h3>Title 1</h3>        
    <p>Speaker 1</p>        
    <p class="ui-li-aside"><b>Time 1</b></p>    
</li>   
<li>
    <h3>Title 2</h3>        
    <p>Speaker 2</p>        
    <p class="ui-li-aside"><b>Time 2</b></p>    
</li>
 <li>
    <h3>Title 3</h3>        
    <p>Speaker 3</p>        
    <p class="ui-li-aside"><b>Time 3</b></p>    
</li>

This works:

$("li:nth-child(0) p.ui-li-aside").insertBefore("li:nth-child(0) h3");

But I don't want to do it for every element.

This doesn't work the way I want it:

$("li:nth-child(n) p.ui-li-aside").insertBefore("li:nth-child(n) h3");

How can I write this in a shorter way and for any element? I can't change the html part, because it is used also on an other page.

likeitlikeit
  • 5,563
  • 5
  • 42
  • 56

1 Answers1

1

You can use prependTo

$(document).ready(function () {
    $('li').each(function () {
        var $this = $(this);
        $('p.ui-li-aside', $this).prependTo($this);
    });
});

Check Fiddle

Sushanth --
  • 55,259
  • 9
  • 66
  • 105