Sort divs alphabetically or numerically (based on content)

by ravimallya

HTML

<script src="http://raw.github.com/abdennour/jquery.sortContent/master/src/jquery.sortcontent.js"></script>
<div id="sortThis">
  <div id="1">Price:<span class="price">20</span> <span class="style">blue</span></div>
  <div id="2">Price:<span class="price">23</span> <span class="style">red</span></div>
  <div id="3">Price:<span class="price"></span> <span class="style">red</span></div>
  <div id="4">Price:<span class="price">29</span> <span class="style">green</span></div>
  <div id="5">Price:<span class="price">35</span> <span class="style">blue</span></div>
</div>

<button id="sPrice" class="btnSort">Asc</button>
<br />
<button id="sStyle" class="btnSort">Desc</button>
<br />

JavaScript

/**
 *jQuery Plugin SortContent
 *
 * https://github.com/abdennour/jquery.sortContent
 * @author Abdennour TOUMI<[email protected]>
 * @requires JQuery
 * @param options {Object} override default values
 * @constructor
 */
/*!
 * jQuery Plugin SortContent
 * Copyright (c) 2013-2014 Estifèda <[email protected]>
 * The MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

(function($) {
  var methdSorContent = {
    hakikaAsl: function(elAsl) {
      //strategy,asc,helper,helperxp,target,format,weight,update
      return elAsl;
    },
    ctyy: function(e, args) {
      return args.target(e).parent();
    },
    updateNiheya: function($th, arryB3dTertib, args) {
      /*methdSorContent.realSelected($th).each(function(i,e){
      	 args['update']($(e),arryB3dTertib[i].scld,arryB3dTertib[i].wcumul);
      });*/
      var e = {};
      var eprv = {};
      for (var i = 0; i < arryB3dTertib.length; i++) {
        e.ui =...