Indeed it doesn't work, i would have liked JS to accept that syntax, but alas...
Ryura, you are correct, if I had been creating an object instead of an array it would have worked. I randomly posted my code with the understanding that everything in JS is treated as an object (including arrays) and stupidly assumed that syntax would work. Frankly I am quite embarrassed, and I apologize for posting bad code. :( For future reference, this will work: var clients = []; clients['nike'] = 'swoosh.jpg'; clients['addidas'] = '3stripes.jpg'; clients['reebok'] = 'rbk.jpg'; clients['default'] = 'default.jpg'; var class = $("#main").attr("class"); typeof clients[class] != "undefined" ? insertImg(clients[class]) : insertImg(clients['default']); function insertImg(path) { $('#main').prepend('<img src="'+path+'"/>'); } On Jul 11, 10:42 pm, Ryura <[EMAIL PROTECTED]> wrote: > Richard's didn't work because he formed an array instead of an object > like he was planning. Replacing the [ ... ] with { ... } should've > made it work. > > On Jul 11, 4:13 pm, brendan <[EMAIL PROTECTED]> wrote: > > > Thanks Richard, I couldn't get yours to work (my js knowledge is > > pathetically rusty) and ran out of time to tinker with it, I ended up > > just prepending the image to the div by class after it's randomly > > added: > > > $(document).ready(function(){ > > $("#main.nike").prepend('<img src="swoosh.jpg" alt="nike" />'); > > $("#main.adidas").prepend("<img src="3stripe.jpg" alt="adidas" />"); > > $("#main.reebok").prepend("<img src="rbk.jpg" alt="reebok" />"); > > > }); > > > Not the cleanest solution but it seems to be working... Thanks again > > noon for your help as well