Thanks, 

Here is the code I used:

$("a.emailitem").click(function(){
        
        var i = $(this).attr("id");
        var y = i.split("|");
        var url = "/emailstory/index/" + y[1];
        $("div.newsitememail:eq(" + y[0] + ")").load(url);
        $("div.newsitememail:eq(" + y[0] + ")").toggle();
        
}
);

I'm going to put the "return false" into this as well.


Karl Swedberg-2 wrote:
> 
> Hi Damian,
> 
> I think you're on the right track, too, but it looks like you might  
> be working too hard to find the right div to toggle.
> 
> The trick is to determine where the "div.newsitememail" element is in  
> relation to the clicked "a.emailitem" in the DOM.
> 
> For example, if each newsitememail is the next sibling of its  
> corresponding emailitem, you can do something like this:
> 
> 
> $("a.emailitem").click(function(){
>       $(this).next().toggle();
>       return false; //important to include so the browser doesn't try to  
> follow the link.
> });
> 
> If you need to be more specific about the element coming next, you  
> can place the details of the element to toggle inside the .next()  
> parentheses:
> .next('div.newsitememail')
> 
> Hope that helps point you in the right direction.
> 
> --Karl
> _________________
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
> 
> 
> 
> On Jul 1, 2007, at 9:42 PM, DamianD wrote:
> 
>>
>>
>> I think i'm on the right track, my code below works...sort of:
>>
>> $("a.emailitem").click(function(){
>>      
>>      $("div.newsitememail:nth(0)").toggle();
>> }
>> );
>>
>> Though, obviously, no mater which "a.emailitem" is clicked - the first
>> newsitememail div is toggled...not exactly what is needed.
>>
>> I tried this:
>>
>> $("a.emailitem").click(function(){
>>      
>>      var i = $(this).attr("id");
>>      $("div.newsitememail:nth(i)").toggle();
>> }
>> );
>>
>> Which I thought should work, but has no effect.  Nothing is  
>> toggled.  It is
>> as if 'var i' is not passed to nth().
>>
>> How can I get the var to pass properly?
>>
>>
>>
>> DamianD wrote:
>>>
>>> Hi,
>>>
>>> How do I toggle a div based on the div's value?
>>>
>>> Example:  The site I am working on has multiple blog posts per page.
>>> Under each post is a menu.  One of the menu items is for emailing the
>>> story.  Under this there is a div that will display the email  
>>> form.  This
>>> div is hidden by default. The link is as follows:
>>>
>>>  # id ?>">Open Email Interface
>>>
>>> This div is:
>>>
>>> <div class = "newsitememail" value = "<?php echo $stroy->id ?>">
>>>
>>> My logic so far has been to grab the link's id using jquery and then
>>> display the appropriate div based on the value (which is the same  
>>> as the
>>> id in the link).
>>>
>>> Here is the jquery code so far:
>>>
>>> $("a.emailitem").click(function(){
>>>     
>>>     var id = $(this).attr("id");
>>> }
>>>
>>> How do I toggle the correct div?
>>>
>>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Toggle-element- 
>> based-on-value-tf4009643s15494.html#a11387195
>> Sent from the JQuery mailing list archive at Nabble.com.
>>
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Toggle-element-based-on-value-tf4009643s15494.html#a11442829
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to