i have the following html:
<div class="pagination">
<a href=".... ?page=1">...</a>
</div>
I need to append to each href some values to query string like this
…?page=1&field=xxx.
I tried this:
$.each('.pagination a',function(){
(this).attr(href).append('&field=x');
});
but it does nothing.
Any ideas?
JavaScript doesn’t have attr methods. You need to work with a jQuery object instead.
For example: $(this)
Ok.
That works.
Another problem:
I have trying to make a table sortable in server side.
I have this in my table headers:
<th><a href="#" "onclick="sortTable('title','desc');">Title</a></th>
My sortTable function:
function sortTable(tb_field,tb_order)
{
$('.loader').show();
$('.container').load(
url ,{field: tb_field,order: tb_order},
function() {
$('.loader').hide();
}
);
}
My problem is: After the first call how do I change the order in onclick event to ‘asc’.
Maybe there is a best way.
Well i have changed my implementation to something cleaner
<th><a class="table_header" href="...?field=titulo&order=desc">Título</a></th>
$('.table_header').click(function(){
$('.loader').show();
var url = $(this).attr('href');
$('.table_container').load(url,
function() {
$('.loader').hide();
My question is:
After the call how do i get the order field from query string and change it´s value from the default desc to asc?
There is a nice querystring library for JavaScript, that will allow you to easily manipulate them.
http://adamv.com/dev/javascript/querystring