<a class="app_store_new_b" href='#' onclick="getAppList(9,'con','title','asc')">Название &#9650;</a> <a class="app_store_new_b" href='#' onclick="getAppList(9,'con','title','desc')">Название &#9660;</a> 

How can I make this one button? When you click on it, sorting up and down is now 2 different buttons.

I started to do, but somehow it turns out loudly on js + css ... I think that there is a simple solution, but there is not enough knowledge

  • on pure js or is it possible on jquery? - Gena Tsarinny
  • on jquery is even preferable - Acht88

1 answer 1

elementarily the same:

 var data = [1,-6,11,3,9,7] , sortData = (function(){ var flag = true // создаём флаг , predicates = { 'asc' : function(a, b){ return (a>b) - (b>a) } , 'desc': function(a, b){ return (a<b) - (b<a) } } return function(data){ flag = !flag // который при каждом вызове переключаем data.sort(predicates[flag ? 'asc' : 'desc']) // и сортируем в зависимости от его значения } }()) sortData(data) console.log(data) // [11, 9, 7, 3, 1, -6] sortData(data) console.log(data) // [-6, 1, 3, 7, 9, 11] sortData(data) console.log(data) // [11, 9, 7, 3, 1, -6] sortData(data) console.log(data) // [-6, 1, 3, 7, 9, 11] 

interactive example: http://jsfiddle.net/psmm6/2/

  • Thank you very much. And then I made pornography with display: none. - acht88