Entries for month: November 2011

AJAX debug

Nice little JS snippet for debuggin JQuery AJAX calls..  For example JQuery $.POST() will fail silently, this will show what went wrong!



 


//AJAX error output help


$.ajaxSetup({


error:function(x,e){


console.log(x.responseText);


alert('AJAX error, check console!');


$("#message_post").empty().append("Error With You AJAX!");


}


});


 

Bookmark and Share

2 Comments

Sort <p> by their ID attribute

This is a example of having <p> tags with numeric id attributes.  For example "<p id="1">", "<p id="2">".  I ran into a situation where there ids were goin from 9-1, and i need them to go 1-9, so i found this little piece to sort the "<p>" by their id attribute.  In this example "clientImages" is a wrapper div for the images and the "<p>'s".



 


//create div placeholders for content.


var clientImages = customersContainer.find('img').parents('p');


//the image <p> are in opposite order we need to reorder them to 1-9 to match description <p>'s'


clientImages.sort(function(a,b){


var compA = $(a).attr('id');


var compB = $(b).attr('id');


return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;


})


 

 

Bookmark and Share

No Comments

Find a string in div class with JQuery

Im not so hot with JQuery selectors... So i found this real useful, was looking for the id attribute of the ahref with a class that contained "selected".



var selectedTab = $('#YOURID').find('a').filter('[class~="selected"]').attr('id');


Bookmark and Share

3 Comments

LIKE with Digits

Little SQL for someone looking for a way to filter a query by a number.



AND title LIKE '[0-9]%'


Bookmark and Share

No Comments