CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   jQuery Selectors (Selecting objects from list's) (http://www.codingforums.com/showthread.php?t=192268)

Eder 03-24-2010 08:06 PM

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

tomws 03-24-2010 09:11 PM

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.

Spudhead 03-25-2010 11:03 AM

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');


:confused:

tomws 03-25-2010 01:24 PM

Wouldn't the children inherit that style? That was my assumption, anyway.

Eder 03-25-2010 08:26 PM

Quote:

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.

funkyapache 03-26-2010 01:09 PM

SO you cant do this http://jsfiddle.net/upAp7/?

Spudhead 03-26-2010 02:11 PM

Quote:

Originally Posted by tomws (Post 936821)
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');
});



All times are GMT +1. The time now is 04:49 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.