Results 1 to 2 of 2

Thread: Jquery $('.class') select only one

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Jquery $('.class') select only one

    Hey everyone!

    I have several divs which all have the class content. Only one div is made visible at a time using this code -

    Code:
    function hidedivs() {
    	//HIDE UN-NEEDED DIVS
    	var contentid=new Array();
    	contentid[0]="con1";
    	contentid[1]="con2";
    	contentid[2]="con3";
    	for(i=0;i<contentid.length;i++) {
    		document.getElementById(contentid[i]).style.display = 'none';
    	}
    }
    function swapcontent(contentid) {
    	hidedivs();
    	//document.getElementById(contentid).style.display = 'block';
    	$('#' + contentid).fadeOut().delay(50).fadeIn(800); 
    	$('#sideBar').fadeOut().delay(50).fadeIn(800); 
    }
    What I'd like to do is get the height of the div that is currently visible and assign it to a variable like this, but it doesn't work...

    Code:
    	$(".content").each(function (w) { 
    		if(w.style.display != "none") {          
    			var heightvar = w.height();      
    		} else {                
    		}      
    	});
    Any help?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There could also be other problems. However, according to the manual:

    http://api.jquery.com/jQuery.each/

    The first parameter in the each function is the index. so w will never have a style property.

    You can either do:

    Code:
    	$(".content").each(function (i, w) { 
    		if(w.style.display != "none") {          
    			var heightvar = w.height();      
    		} else {                
    		}      
    	});
    Or:

    Code:
    	$(".content").each(function () { 
    		if(this.style.display != "none") {          
    			var heightvar = w.height();      
    		} else {                
    		}      
    	});
    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 1
    Last Post: 08-09-2011, 06:29 AM
  2. Resolved jQuery Multi Level CSS Menu #2 drop down behind "select" item on page
    By SuperCrispy71 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 04-21-2010, 11:45 AM
  3. Replies: 2
    Last Post: 10-09-2009, 04:19 PM
  4. jQuery hide() and show() based on a select element.
    By nicksalad in forum JavaScript
    Replies: 3
    Last Post: 10-08-2009, 12:28 PM
  5. psudo-class within a class?
    By agentphish in forum CSS
    Replies: 1
    Last Post: 10-27-2008, 07:20 PM

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
  •