SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    391
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Create jQuery Selector in For loop

    Hi,

    I'm new to javascript and am trying to create a For loop to create iterated selector class names so that i can target specific divs. Here is the code im trying to implement:

    Code:
    <script>
    		$(document).ready(function() {
    			
    			$( ".tabRow" ).hide();
    			for ( var i = 0; i < <?php echo $this->_data['productCount']; ?>; i++ ) {
    				var productRowInt = '.productRow' + i;
    				var tabRowInt = '.tabRow' + i;
    				$(productRowInt).click(function() {
    					$(tabRowInt).toggle();
    				});
    			}
    			
    		});
    	</script>
    I can see in Firebug that the var's have been setup but nothing is happening. How should i insert a selector from a javascript var?

    Thanks!

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Your code seems fine at first glance.
    Could you post a link to a page where I can see this not working?


Bookmarks

Posting Permissions

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