Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Getting elements like in CSS
Old 10-01-2008, 05:59 AM Getting elements like in CSS
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
I'm wondering how I would get an element's value like you would set a style with CSS.

eg
HTML Code:
<p id="para"><a href=""><img src=".jpg" /></a></p>
using CSS:
Code:
p#para a img { border: 2px solid black; }
Is it possible to use this method (Which I don't know any terms for) in Javascript? I only know the basic DOM method:

document.GetElementById("para").value;

I'm wondering how you would go about doing the same thing above in CSS, something like this [in theory]

document.getElementById("para").a.img.style = "border: 2px solid black;";


I know how I could do workarounds, but I've wondered if this was possible for too long. I just need to know how to do it, I can't search for it because I don't know what this type of method is called.
RadGH is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-01-2008, 08:46 AM Re: Getting elements like in CSS
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
To do directly it would be

Code:
document.getElementById("para").firstChild.firstChild.style.border = "2px solid black;";
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-01-2008, 08:49 AM Re: Getting elements like in CSS
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
BTW

It's called "Walking the DOM tree"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Getting elements like in CSS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12109 seconds with 12 queries