Entries for month: November 2011
AJAX debug
Posted by Erik Ruthven in Javascript , Random on November 21, 2011
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!");
}
});
Sort <p> by their ID attribute
Posted by Erik Ruthven in Javascript , Random on November 21, 2011
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;
})
Find a string in div class with JQuery
Posted by Erik Ruthven in Javascript , Random on November 18, 2011