tag attributes, HTML and CSS

M

Matko

Hi dear web people,

DHTML's DOM document.getElementById("id").attributes gives me array of
HTML attributes written inside html. document.

How could i get those defined in CSS file (e.g. margin, padding, width and
height) ?

Regards,

Matko
 
C

Captain Paralytic

Hi dear web people,

  DHTML's DOM document.getElementById("id").attributes gives me array of
HTML attributes written inside html. document.

How could i get those defined in CSS file (e.g. margin, padding, width and
height) ?

Regards,

Matko

Your question is quite ambiguous and I cannot tell precisely what you
are asking for.
To make it clearer, please tell me which of the hits you got when you
searched google for:
javascript get css
(you did do this sort of search didn't you?) are the closest to what
you are askign and in what way they did not answer your question.
 
J

Jukka K. Korpela

Matko said:
DHTML's DOM document.getElementById("id").attributes gives me array
of HTML attributes written inside html. document.

Yes, though the buzzword "DHTML" is rather dated.
How could i get those defined in CSS file (e.g. margin, padding,
width and height) ?

It depends on what you mean by that. You can use HTML attributes in
attribute selectors in CSS. And you can modify stylesheets using Javascript.

As usual, posting a URL and explaining what you wish to achieve (how to
enhance the page) would be a good start.
 
M

Matko

Matko said:
Hi dear web people,

DHTML's DOM document.getElementById("id").attributes gives me array of
HTML attributes written inside html. document.

Sorry, i ment HTML div tag attributes...
How could i get those defined in CSS file (e.g. margin, padding, width and
height) ?

Regards,

Matko

For example:

<html>
.....
<link rel="stylesheet" type="text/css" href="style.css">
.....
<div id="identifier">
<p>Paragraf inside a div tag. Paragraf inside a div tag. Paragraf inside a
div tag.</p>
Text inside a div tag. Text inside a div tag. Text inside a div tag.
</div>
.....
</html>
document.getElementById("identifier").attributes returns only 1 div tag
attribute, an that is "id" with value "identifier".

What i want to get are attribute values which i have set up inside of css
file and which have (of course) been applied to
HTML div tag, aren't they? I'm especially interested in width and height.

I suppose CSS values became part of DOM object properties, aren't they?

e.g:
#identifier {
margin:0;
padding:0;
background: #303;
list-style-type: none;
width: 160px;
text-align: center;
}

I said DHTML DOM because i read somewhere that there is also xml DOM, isn't
that corect?

Thank You very much for Your response. I appreciate Your contribution!

Matko
 
R

richard

Sorry, i ment HTML div tag attributes...


For example:

<html>
....
<link rel="stylesheet" type="text/css" href="style.css">
....
<div id="identifier">
<p>Paragraf inside a div tag. Paragraf inside a div tag. Paragraf inside a
div tag.</p>
Text inside a div tag. Text inside a div tag. Text inside a div tag.
</div>
....
</html>
document.getElementById("identifier").attributes returns only 1 div tag
attribute, an that is "id" with value "identifier".

What i want to get are attribute values which i have set up inside of css
file and which have (of course) been applied to
HTML div tag, aren't they? I'm especially interested in width and height.

I suppose CSS values became part of DOM object properties, aren't they?

e.g:
#identifier {
margin:0;
padding:0;
background: #303;
list-style-type: none;
width: 160px;
text-align: center;
}

I said DHTML DOM because i read somewhere that there is also xml DOM, isn't
that corect?

Thank You very much for Your response. I appreciate Your contribution!

Matko

Ask your question in comp.lang.javascript
 
D

Denis McMahon

Hi dear web people,

DHTML's DOM document.getElementById("id").attributes gives me array of
HTML attributes written inside html. document.

How could i get those defined in CSS file (e.g. margin, padding, width and
height) ?

Look at the style attribute for the element - also this is really a
javascript question and not an html one, try and ask in the right place
next time.

eg:

var idMarginStr = document.getElementById("id").style.margin;
var idPaddingStr = document.getElementById("id").style.padding;
var idWidthStr = document.getElementById("id").style.width;
var idHeightStr = document.getElementById("id").style.height;

(note these are all string values and may be any valid css for element
and css property, or an empty string if no style is set is set for the
element / property combination)

and

document.getElementById("id").style.margin = "10px 30px";
document.getElementById("id").style.padding = "1em";
document.getElementById("id").style.width = "600px";
document.getElementById("id").style.height = "400px";

Rgds

Denis McMahon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top