How can i get specific child elements of $(this)
Hello. Im working through the book bulletproof ajax, and for a chapter, im putting in jquery functionality instead of the ones provided with the book. I have run into some trouble.
The prepare rating function does not work correctly. Id like to replace first like with something like $(this).$('a'), however that does not work. Basically the jQuery replacement for: this.getElementsByTagName('a');
-
$(document).ready(function() {
bookShop();
});
function bookShop() {
var prepareCart = function(element) {
$(element).click(function() {
var amount = $('input[name=amount]');
var product = $('input[name=product]');
$.ajax({
method: 'POST',
url: 'shoppingcart.php',
data: 'amount='+ amount + '&product='+product,
success:function(response) {
$('#basket').html(response)
.effect('highlight', {}, 2000);
}});
return false;
});
};
var prepareRating = function(element) {
$('div.rating a').each(function() {
$(this).click(function() {
$.ajax({
method: 'POST',
url: 'rating.php',
data: $(this).attr('href').split('?')[1],
success:function(response) {
$(element).html(response)
.effect('highlight', {}, 2000);
}
});
return false;
});
});
};
$('form.shopping').each(function() {
prepareCart($(this));
});
$('div.rating').each(function() {
prepareRating($(this));
});
}