Sunday, 29 September 2013

Add random class to an Appended div ? (jquery)

Add random class to an Appended div ? (jquery)

This is all of my code for the object I'm working with, but I'm thinking
it's only the "create building in screen" part you really need to help me
with.
My goal is to have it where instead of saying class="House houseRed", it
says something like class="House +'randomClass'" etc, and that variable
holds my other class names(i have 5 total). It's for a mini-game I'm
working on, and I need the buildings that spawn to have different looks,
based on their class names.
//CREATE BUILDING IN MEMOMORY
function CreateHouseInMemory() {
//GET VALUES
var sAddress = $("#HouseAddress").val();
var sUniqueId = getUniqueId();
var iMaxResidents = $('input[name=housemaxresidents]').val();
var oHouse = {
sType: "House",
sAddress: sAddress,
sId: sUniqueId,
iMaxResidents: iMaxResidents,
Residents: aResidents = [],
babyInHouse: false
};
oCity.aBuildings.push(oHouse);
console.dir(oCity.aBuildings);
return oHouse;
}
//CREATE BUILDING IN SCREEN
function CreateHouseInScreen(oHouse)
{
$("#City").append('<div id="' + oHouse.sId + '" class="House
houseRed" title="' + oHouse.sAddress + '"></div>');
$(".House").draggable();
$(".House").droppable();
}
;
//SPAWN BUILDING
$("#BtnCreateHouse").click(function() {
var oHouse = CreateHouseInMemory();
CreateHouseInScreen(oHouse);
});

No comments:

Post a Comment