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

http://jsfiddle.net/5fap4/

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" ); 

updated jsfiddle


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -