javascript - Sort divs using jQuery based on child elements content -


i'm trying sort n amount of divs in page based on content inside other elements in div.

here html code looks 1 div block (in 1 page there several need re-order / sort price or alphabetically.

<div class="productboxwrapper"> <li>     <img src="my-product-image.jpg"></a>     <div class="product-info">         <h4>             <!-- need sort divs product name -->             <a class="producttitleforsorting" href="product-page-link">product name</a><br>         </h4>         <div class="product-price">             <span id="listprice">suggested retail: $xx.xx</span>             <span id="lowestprice">as low as:                             <!-- need sort divs product price -->             <span class="productpriceforsorting">$xx.xx</span></span>         </div>                    </div>                    </li> </div> 

i'm using jquery plugin http://net.tutsplus.com/tutorials/javascript-ajax/sorting-values-with-javascript/ , jquery.datasource. examples of plugin work, can't work site.

here javascript that's triggered when user selects sorting option (price, alpha) dropdown list. random sorting sometimes, not work properly. i'm afraid i'm not calling right div here or ... i'm new jquery appreciated. please see plugin page usage

change: function () {  var selectedoptionvalue = jquery('#sortthiscollectionbaby option:selected').val();  if (selectedoptionvalue == 'price-low-to-high') {                 // sort collection price - low high          jquery('.productboxwrapper').fadeto("fast", 0.5);         var $this = jquery(this);          jquery('.productboxwrapper').datasort({             datatype: 'alpha',             sortelement: '.productpriceforsorting',             reverse: false         });            jquery('.productboxwrapper').fadeto("fast", 1); }      if (selectedoptionvalue == 'price-high-to-low') {         // sort collection price - high low         jquery('.productboxwrapper').fadeto("fast", 0.5);         var $this = jquery(this);                 jquery('.productboxwrapper').datasort({             datatype: 'alpha',             sortelement: jquery('.productpriceforsorting'),             reverse: true         });               jquery('.productboxwrapper').fadeto("fast", 1);   }      if (selectedoptionvalue == 'alphabetically-a-to-z') {         // sort collection alphabetically z                 jquery('.productboxwrapper').fadeto("fast", 0.5);         var $this = jquery(this);                 jquery('#producttitleforsorting').datasort({             datatype: 'alpha',             sortelement: '.producttitleforsorting',             reverse: false                       });                 jquery('.productboxwrapper').fadeto("fast", 1); }  if (selectedoptionvalue == 'alphabetically-z-to-a') {         // sort collection alphabetically z         jquery('.productboxwrapper').fadeto("fast", 0.5);         var $this = jquery(this);                 jquery('.productboxwrapper').datasort({             datatype: 'alpha',             sortelement: '.producttitleforsorting',             reverse: false         });         jquery('.productboxwrapper').fadeto("fast", 1);    } } 

something looks wrong jquery('.productboxwrapper'). shouldn't sorting li's, should jquery('.productboxwrapper li').


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -