Jump to content

Calling CSS in Javascript


locbtran

Recommended Posts

in HTML you can call CSS

<head><link rel="stylesheet" type="text/css" href="style.css" /></head><tr><td class="cssHere">Display</td></tr>

can you even call CSS in javascript?

document.writeln("<tr><td class="cssHere">" + Display + "</td></tr>");

if so how do you even call the "style.css"thanks

Link to comment
Share on other sites

with you javascript you can get a reference to an element a few different ways, such as with document.getElementById or getElementByTagName. With this reference you can change any CSS property or element property you need, like it's class.http://www.w3schools.com/jsref/prop_html_classname.aspyou could probably append a link relation to the <head> element of a document if you needed to. Personally, I wouldn't use document.write. There are much more elegant solutions, such as innerHTML, that won't overwrite the document.

Link to comment
Share on other sites

you can also read the values of style properties but only for inline styles of elements. I'm not sure how you would read the computed style of an element, such as the color of an element, if it was applied in an external stylesheet or style block somewhere on your page.jQuery actually will read the computed styles of an element that is wrapped in the jQuery object using the .css() method and passing it no arguments. No idea how it does this though.

Link to comment
Share on other sites

you can also read the values of style properties but only for inline styles of elements. I'm not sure how you would read the computed style of an element, such as the color of an element, if it was applied in an external stylesheet or style block somewhere on your page.jQuery actually will read the computed styles of an element that is wrapped in the jQuery object using the .css() method and passing it no arguments. No idea how it does this though.
There's a getComputedStyle() method in some browsers, and an alternative of some sort for Internet Explorer. A quick Google search would find it.
Link to comment
Share on other sites

you can also read the values of style properties but only for inline styles of elements. I'm not sure how you would read the computed style of an element, such as the color of an element, if it was applied in an external stylesheet or style block somewhere on your page.
Try this.
Link to comment
Share on other sites

thanks! i didn't know about those methods for reading style properties. i always wondered how jQuery did that. that was a great article that summed it up too.
You can thank Dierdre's Dad for that article. Sophox is his blog. (Or at least that's what I've been told :) )
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...