I use ajax creat html, like this
html += "<div class=\"cloumns rentprice\">" + data[i].car_price + "</div>";
and I want to catch the json's value use for index form this Dynamic html,
then sorting,
my sorting code like this
$("#rentPrice").click(function(){
var $this=$(this);
$("#rentPrice").not($this)
if ($this.hasClass("up")){
$this.removeClass().addClass("down");
}else{
$this.removeClass().addClass("up");
}
var index = $(".rentprice").text();
var direction =$this.attr("class");
sort(index,direction);
show(json);
});
function sort(index, direction){
json.sort(function(a,b){
var keys = Object.keys(a);
if (direction == "up"){
if (a[keys[index]] > b[keys[index]]){
return 1;
}else if (a[keys[index]] < b[keys[index]]){
return -1;
}else{
return 0;
}
}else{
if (a[keys[index]] < b[keys[index]]){
return 1;
}else if (a[keys[index]] > b[keys[index]]){
return -1;
}else{
return 0;
}
}
});
}
});
, but the answer is wrong , because var index = $(".rentprice").text();
can't get data[i].car_price
for index,
I don't know how to get data[i].car_price
form html , How can I do ?Have any idea?