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 11-10-2011, 03:16 AM   PM User | #1
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
Append Div Elements for div.length

All,
I have the following bit of code:
Code:
<script>
jQuery(document).ready(function() {
	var url='http://search.twitter.com/search.json?callback=?&q=test';
		jQuery.getJSON(url,function(json){
			jQuery.each(json.results,function(i,review){
				jQuery("#divroller_container").append('<div class="reviews" id=item'+i+'>'+review.text+'<br>Reviewed By: '+review.from_user+'</div>');
				//jQuery("#divroller_container".children()[i]).hide();
			});
		});
	});

	var hiddenDivs = [];

	function start(pause, visible_divs) {
		var container = jQuery("#divroller_container");
		var divs = container.children();
		var visible = visible_divs
		alert(divs.length);
		while (visible < divs.length) {
			var removedDiv = jQuery(divs[divs.length - 1]).remove();
			hiddenDivs.push(removedDiv);
			divs = container.children();
		}
		
		setTimeout( function() {
			roll(container, pause, visible)
		}, pause);
	}
	
	function roll(container, pause, visible) {
		container.prepend(hiddenDivs.pop());
		hiddenDivs.unshift(jQuery(container.children()[visible]).remove());
		
		//Efect
		jQuery(container.children()[0]).hide();
		jQuery(container.children()[0]).slideDown("slow");

		//Repeat
		setTimeout( function() {
			roll(container, pause, visible)
		}, pause);
	}
</script>

<div id="divroller_container">
</div>
<script type="text/javascript">
	start(2000, 1);
</script>
I'm baiscally trying to get some twitter feeds and the rotate them. I can get it and everything like that but for some reason the jQuery doesn't pick up the divs that I appended to the container because when I alert the div.length like this:
Code:
alert(divs.length);
The result is always zero. The code works fine if I can populate that value but if I don't have it in the code before hand it doesn't work. However if I add a div to the container like this:
Code:
<div id="item1" class="reviews">
	<a href="http://ilkinbalkanay.blogspot.com/2007/11/my-favorite-shell-commands.html">My favorite shell commands</a>
</div>
That same code:
Code:
alert(divs.length);
Will output a 1. I'm not sure how to have jquery recognize that I appended the divs earlier. Any help would be great! Thanks in advance!

Last edited by treeleaf20; 11-10-2011 at 06:07 PM..
treeleaf20 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 01:36 AM.


Advertisement
Log in to turn off these ads.