One way (assuming there is only one a.boldFont, and its position is
unknown and may change):

// store a list of all anchors in the target div...
var anchors = $('#eventlist a');

// then when(ever) you need to...
// ...find the position of the boldFont anchor within the stored list
var bf = anchors.index($('a.boldFont', anchors)[0])
// ...put the anchor following the boldfont anchor (if there is one)
into a list
   , clk = anchors.slice(bf+1,bf+2);
// ...add the preceding anchor (if there is one) to the new list
if(bf > 0) clk.add(anchors[bf-1]);
// ...trigger click on the list contents (1 or 2 anchors)
clk.trigger('click');

On Jan 31, 3:26 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hallo,
>
> I am quite new to Jquery and so please forgive me if my problem sounds
> dumb ;)
>
> HTML:
>
> <div id="eventlist">
>    <img src=".."/><a href="#">One</a><br/>
>    <img src=".."/><a href="#">Two</a><br/>
>    <img src=".."/><a href="#">Three</a><br/>                            
> <--------------------------
>
>    <img src=".."/><a href="#" class=".boldFont">Four</a><br/>
>    <img src=".."/><a href="#">Five</a><br/>                                
> <--------------------------
>
>    <img src=".."/><a href="#">Six</a>
> </div>
>
> Problem:
>    I have to access the anchor above the anchor wih class "boldFont"
> and the anchor below the anchor with class ".boldFont".I tried using
> the following statements, it worked partially, but i definitely would
> like to find a clear n neat solution.
>
> My code:
>    $
> ("#eventlist").find("a.boldFont").next().next().next().trigger('click');
>    $
> ("#eventlist").find("a.boldFont").prev().prev().prev().trigger('click');
>
> For now, it may work since there are only three to four elements
> between the anchor. But, if there are N-elements, icannot just go on
> writing "next()" !!???!

Reply via email to