Simple $(document).ready question
I am working from the VanDyk / Westgate Pro Drupal Development book
with (working) code below. I have modified it slightly (also below).
My code breaks--that is, the first $('a.targetme') works, but not the $
("a.unit"). I SUSPECT the problem arises because there is NO $
("a.unit") when the document loads. You first must click the $
('a.targetme'). Any thoughts?
Code from Westgate book
=====================
// $Id$
// Global killswitch
if (Drupal.jsEnabled) {
$(document).ready(function(){
$('a.plus1-link').click(function(){
var voteSaved = function (data) {
var result = Drupal.parseJson(data);
$('div.score').fadeIn('slow').html(result['score']);
$('div.vote').html(result['voted']);
}
$.get(this.href, null, voteSaved);
return false;
});
});
}
================
// Global killswitch
if (Drupal.jsEnabled) {
$(document).ready(function(){
$('a.targetme').click(function(){
var listUnits = function (data) {
var result = Drupal.parseJson(data);
$('div.units').html(result['units']);
$('div.units').css('display','inline');
$('div.units').fadeIn('slow');
}
$.get(this.href, null, listUnits);
return false;
});
$("a.unit").click(function(){
$('a.unit'.css('background','red'));
var listRes = function (data) {
var result = Drupal.parseJson(data);
$('div.unitres').html(result['unitres']);
$('div.unitres').css('display','inline');
$('div.unitres').fadeIn('slow');
}
$.get(this.href, null, listRes);
return false;
});
});
}