Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-24-2010, 08:06 PM   PM User | #1
Eder
New to the CF scene

 
Join Date: Mar 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Eder is an unknown quantity at this point
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..
Eder is offline   Reply With Quote
Old 03-24-2010, 09:11 PM   PM User | #2
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
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?
tomws is offline   Reply With Quote
Users who have thanked tomws for this post:
Eder (03-25-2010)
Old 03-25-2010, 11:03 AM   PM User | #3
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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');


Spudhead is offline   Reply With Quote
Old 03-25-2010, 01:24 PM   PM User | #4
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Wouldn't the children inherit that style? That was my assumption, anyway.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 03-25-2010, 08:26 PM   PM User | #5
Eder
New to the CF scene

 
Join Date: Mar 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Eder is an unknown quantity at this point
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..
Eder is offline   Reply With Quote
Old 03-26-2010, 01:09 PM   PM User | #6
funkyapache
New to the CF scene

 
Join Date: Mar 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
funkyapache is an unknown quantity at this point
SO you cant do this http://jsfiddle.net/upAp7/?
funkyapache is offline   Reply With Quote
Old 03-26-2010, 02:11 PM   PM User | #7
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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');
});
Spudhead is offline   Reply With Quote
Users who have thanked Spudhead for this post:
Eder (03-26-2010)
Reply

Bookmarks

Tags
dom, html, jquery, list, selectors

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:44 PM.


Advertisement
Log in to turn off these ads.