Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

    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.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •