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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Selectors (Selecting objects from list's)


    Hi all,
    I have a problem when selecting objects from a list, example:



    Code:
    XHTML:
    
    <li class="down">Main Text				
        <ul>	
            <li><a href="#text-1">text-1</a></li>
    	<li><a href="#text-2">text-2</a></li>
    	<li><a href="#text-3">text-3</a></li>
    	<li><a href="#text-4">text-4</a></li>
       </ul>
    </li>

    I've already tried something like this, but i can't access Main Text


    Code:
    jQuery:
    
    jQuery("li.down").each(function() {
        
    });
    What I want to retreive is the object that represents Main Text, so then latter, I could be able to format it's style

    Thanks in Advance,
    Eder Quiñones
    Last edited by Eder; 03-24-2010 at 08:09 PM.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    There might be a more elegant way to do it, but a quick and easy hack would be to wrap the text in a span tag. That would remove the ambiguity of the selectors/functions I've looked at and only accesses the desired text as opposed to all contents like text() does.
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    Eder (03-25-2010)

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    if you just want to format the text style, why do you need to get the object at all?

    jQuery("li.down").css('color','#f00');



  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Wouldn't the children inherit that style? That was my assumption, anyway.
    Are you a Help Vampire?

  • #5
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Wouldn't the children inherit that style? That was my assumption, anyway.
    You're right!
    By the way, I can't wrap the text in "span" tags, because it'll change my menu's behavior.
    Last edited by Eder; 03-25-2010 at 08:28 PM.

  • #6
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    SO you cant do this http://jsfiddle.net/upAp7/?

  • #7
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by tomws View Post
    Wouldn't the children inherit that style? That was my assumption, anyway.
    Only if a more specific style rule hasn't already been set for them -

    Code:
    <style type="text/css">
    	.down {color:#000;}
    	.down ul li a{color:#0c0;}
    </style>
    Code:
    <ul>
    	<li class="down">Main Text				
    		<ul>	
    			<li><a href="#text-1">text-1</a></li>
    			<li><a href="#text-2">text-2</a></li>
    			<li><a href="#text-3">text-3</a></li>
    			<li><a href="#text-4">text-4</a></li>
    	   </ul>
    	</li>
    </ul>
    Code:
    $(document).ready(function(){
    	jQuery("li.down").css('color','#c00');
    });

  • Users who have thanked Spudhead for this post:

    Eder (03-26-2010)


  •  

    Tags for this Thread

    Posting Permissions

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