Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2010, 05:10 PM   PM User | #1
many_tentacles
Regular Coder

 
Join Date: Dec 2005
Location: UK
Posts: 207
Thanks: 6
Thanked 2 Times in 2 Posts
many_tentacles is an unknown quantity at this point
Alternating appends...

Hi

I have 2 divs with the numbers 1-3 in them.

I then use jquery to specify whether the numbers are odd or even...

Trouble is it does not reset the odds/evens when it starts the second div.


Here's the code, hope you know what I mean...

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){		
    	$('p:odd').append('even');
		$('p:even').append('odd');
	});
</script>
</head>

<body>

<div>
<p>1 </p>
<p>2 </p>
<p>3 </p>
</div>

<div>
<p>1 </p>
<p>2 </p>
<p>3 </p>
</div>

</body>
</html>
Thanks
many_tentacles is offline   Reply With Quote
Old 02-13-2010, 03:52 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,584
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
How about:
Code:
$(document).ready(function(){		
    	$('div p:odd').append('even');
	$('div p:even').append('odd');
});
?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 02-15-2010, 09:30 AM   PM User | #3
many_tentacles
Regular Coder

 
Join Date: Dec 2005
Location: UK
Posts: 207
Thanks: 6
Thanked 2 Times in 2 Posts
many_tentacles is an unknown quantity at this point
nope... same result...
many_tentacles is offline   Reply With Quote
Old 02-15-2010, 11:45 AM   PM User | #4
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
I think you'll need to apply it to each div, otherwise it's looking for p tags within the scope of the whole document:

Code:
$('div').each(function(){
	$(this).find('p:odd').append('even');
	$(this).find('p:even').append('odd');
});
Spudhead is offline   Reply With Quote
Users who have thanked Spudhead for this post:
many_tentacles (02-15-2010)
Old 02-15-2010, 12:08 PM   PM User | #5
many_tentacles
Regular Coder

 
Join Date: Dec 2005
Location: UK
Posts: 207
Thanks: 6
Thanked 2 Times in 2 Posts
many_tentacles is an unknown quantity at this point
perfect... thanks
many_tentacles is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:06 AM.


Advertisement
Log in to turn off these ads.