Enjoy an ad free experience by logging in. Not a member yet?
Register .
03-24-2010, 08:06 PM
PM User |
#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 ..
03-24-2010, 09:11 PM
PM User |
#2
Senior Coder
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.
Users who have thanked tomws for this post:
03-25-2010, 11:03 AM
PM User |
#3
Senior Coder
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');
03-25-2010, 01:24 PM
PM User |
#4
Senior Coder
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.
03-25-2010, 08:26 PM
PM User |
#5
New to the CF scene
Join Date: Mar 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
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.
Last edited by Eder; 03-25-2010 at 08:28 PM ..
03-26-2010, 01:09 PM
PM User |
#6
New to the CF scene
Join Date: Mar 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
03-26-2010, 02:11 PM
PM User |
#7
Senior Coder
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Quote:
Originally Posted by
tomws
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:
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 07:44 PM .
Advertisement
Log in to turn off these ads.