I'm new and stuck! trying to use a variable as a selector...

I'm new and stuck! trying to use a variable as a selector...

I am extremely new to jQuery, I was extremely excited when I first found it, as I was struggling with learning javascript on its own... things were really starting to click, but now I'm stuck, and I cant seem to figure it out on my own.

I'm building an ajax module that displays products. I started building a sort of prototype just to get the functionality down. Basically the panel shows three products, including an image and some information included in the xml...

this.ajaxCallTest = function() {
$.ajax({
type: "GET",
url: "specialOfferings.xml",
dataType: "xml",
success: parseXml
});

$("body").append("<div id='specialsModule'><ul></div>")


function parseXml(xml) {
$(xml).find('unit').each(function() {
var $unit = $(this);
var model = $unit.find('model').text();
var make = $unit.find('make').text();
var sn = $unit.find('sn').text();
var type = $unit.find('type').text();
var year = $unit.find('year').text();
var ss = $unit.find('ss').text();
var fuel = $unit.find('fuel').text();
var model = $unit.find('model').text();
var hours = $unit.find('hours').text();
var thumbUrl = $unit.find('sn').text() + "_thumb.jpg";
var imageUrl = ($unit.find('sn') + '.jpg');
var detailsLink = '<a class="specialsLink">Click for More Info!</a>';

var unitInfo = '<li>';
unitInfo += '<h5 class="specialsImgTitle"> '+ year + make + model +' </h5>';
unitInfo += '<img alt="" src="' + thumbUrl + '" />';
unitInfo += detailsLink;
unitInfo += '</li>';
$("#specialsModule ul").append($(unitInfo));
$(detailsLink).click(function(){
$(body).append("<p>" + this.model + "</p>");
});



});

}
};

$(document).ready(function(){

ajaxCallTest();

});

My problem is this: when the detailsLink is clicked, I want to populate a div with more information stored in other variables pertaining to the individual products. I thought i could just pass that variable in a click event, and then use .this statements to grab the other variable.

I'm not sure if I'm even explaining my problem correctly, as I said I'm very new to this... Any help would be awesome!


thanks, alex
    • Topic Participants

    • alex