javascript - Ordinate Div by H1 name -
i sort in alphabetical order of box using h1 tag.
this the code:
<div id="test"> <div class="box"> <div class="internalbox"> <h1><a href="http://www.example-t.it">third</a></h1> <p>sem lacinia quam venenatis vestibulum.</p> </div> </div> <div class="box"> <div class="internalbox"> <h1><a href="http://www.example-f.it">first</a></h1> <p>sem lacinia quam venenatis vestibulum.</p> </div> .... </div> <script> $( ".box h1", "#test" ).sort(function( a, b ) { return $( ).parents('.box').html() > $( b ).parents('.box').html(); }).appendto( "#test" ); </script>
and here example
how can do?
thanks
this seems work:
$(".box").sort(function(a, b) { return $(a).find("h1").text() > $(b).find("h1").text() ? 1 : -1; }).appendto( "#test" );
Comments
Post a Comment