Hi Sperks I'm a bit new at JQuery and have been following what you have done here. I'm trying though to add a third id in and can't figure out how to get it to work with an additional set of div's or more for that matter. Can you help?
On Feb 22, 2:33 pm, sperks <[EMAIL PROTECTED]> wrote: > I worked a little longer and in case anyone has been watching trying > to work out what I was on about... Here's my final code. I don't > thinks it's very clean, and I'm sure there are easier ways of doing > this, ways that don't require me to name the ids, etc., but I'm not > familiar with the intricate workings of math functions. Heck I'm proud > I got this far. > > $(document).ready(function() { > var ids = [ 'latestArticle', 'inTheMag' ]; > var index = Math.round( Math.random()*10 ) % 2; > var id = ids[ index ]; > $('#mainArticle #' + id + ' .teaser').hide(); > $('#mainArticle #' + id + ' h1 span').addClass("hidden"); > $('#mainArticle > div h1').click(function(){ > var place = $(this).parent().attr("id"); > $('#mainArticle h1 span').addClass("hidden"); > $('#' + place + ' h1 span').removeClass("hidden"); > $('#mainArticle .teaser').hide(); > $('#' + place + ' .teaser').slideDown('slow'); > }); > > }); > > On Feb 21, 6:32 pm, sperks <[EMAIL PROTECTED]> wrote: > > > update: > > > I'm still looking for the random side of things, but I've got "a" > > solution for the switching. However, I'm a little concerned that I'm > > targeting h1 rather than the span (how do I go back two parents?) > > > $(document).ready(function() { > > $('#mainArticle #latestArticle .teaser').hide(); > > $('#mainArticle #latestArticle h1 span').addClass("hidden"); > > $('#mainArticle > div h1').click(function(){ > > var place = $(this).parent().attr("id"); > > $('#mainArticle h1 span').addClass("hidden"); > > $('#' + place + ' h1 span').removeClass("hidden"); > > $('#mainArticle .teaser').hide(); > > $('#' + place + ' .teaser').slideDown('slow'); > > }); > > > });