I want to know the most efficient and good practice on accomplishing the following. The case is simple: if you click prev link decrease pagenum or increment if you click next link.Then send it to a function along with its parent data.
I know how to do this by doing two different function for on, but i want a simple, and faster approach.
Html:
<div>
hello world
<a class="prevpg>Previous</a>
<a class="nextpg">Next</a>
</div>
javascript:
$(document).on('click', '.prevpg, .nextpg', function(){
var element = $(this).parent('div').text();
// if ,prevpg was clicked
somefunction(pagenum--, element)
// else if .nextpg clicked
somefunction(pagenum++,element)
})
function somefunction(pagenum, data ){
var test = true;
if(data == 'hello world'){
test = false; }
$.ajax({
url: 'search',
type: 'GET',
data: {'pagenumber':pagenum, testdata: test} ,
dataType: 'json',
success: function(res){
$('body').append(res.data);
}
});
}