On 10/11/07, Yasmary Mora <[EMAIL PROTECTED]> wrote: > > > Hello! > > Got a question that I havn't been able to answer. This is my last resort. > :) > > So, I have a list of dynamically created divs, with a link next to > them to show or hide text inside of it. I know how to do it when its > only a single box, but I dont know how to do it with a dynamic list. > > The whole script gets created with php, so I don't know how many divs > there'll be. Normally I do the whole thing with javascript but I > really like jQuery, and I wanted to try to stick to using it. > > So the result of the php script is something like this: > > <a href="#" id=showtxt[1]">show text</a><div id="textbox[1]">Text > here</div> > <a href="#" id=showtxt[2]">show text</a><div id="textbox[2]">Text > here</div> > <a href="#" id=showtxt[3]">show text</a><div id="textbox[3]">Text > here</div> > <a href="#" id=showtxt[4]">show text</a><div id="textbox[4]">Text > here</div> > > The jQuery code I have works for only one box... > > $('#showtxt').click(function() { > $('#textbox').slideToggle(400); > return false; > }); > > > I've tried for the past 2 hours to figure it out, and I've had no > luck. I think I might be using the wrong wording to describe my > problems, but either way I have no idea exactly what I'm looking for. > Any help is appreciated. :o) > > Thanks in advance! > > -- > -Yasmary >
Here is one way it could be done: $("[EMAIL PROTECTED]'showtxt']").click(function() { var i = this.id.match(/showtxt\[(\d)+\]/); if (!!i[1]) { var $textBox = $("[EMAIL PROTECTED]'textbox["+i[1]+"]']"); if (!!$textBox) $textBox.slideToggle(400); } return false; }); Note: in your example HTML, it looks like you left off the opening quote on the showtxt ID.