Jump to content

"string".method('param');


Drycodez

Recommended Posts

string.style.color;

This is a property of the string and will (if declared) output the current color of the string. In order to change the color you need to assign the property with a value. For instance:

string.style.color = "red";

Link to comment
Share on other sites

Do some reading. CSS properties that contain a hyphen are accessed in JavaScript using camelCase:var myElement = document.getElementById('test');myElement.backgroundColor = "#000";Why would someone design an interface that allowed you to access some CSS properties but not all properties? That makes no sense. The web is worth $billions, not something designed by children.

Link to comment
Share on other sites

Here's a good page to look at: http://www.w3schools.com/jsref/dom_obj_style.asp
since the styleObj is all to do with CSS, could one say that CSS is a "subset" of JS in terms of DOM manipulation(?) - not dissimilar to jQuery, in that it has it's own set of delimiters(?) but basically the same syntax.maybe not "JS" but it seems like what we learn as JS is the handling of the DOM(structure); while CSS does the DOM(presentation) and jQuery, as a JS extension, the DOM(behaviour).
Link to comment
Share on other sites

jQuery doesn't do anything that you can't do with Javascript alone, it just makes some tasks easier. jQuery is not part of the native Javascript functionality while the style object is.

Link to comment
Share on other sites

jQuery doesn't do anything that you can't do with Javascript alone, it just makes some tasks easier. jQuery is not part of the native Javascript functionality while the style object is.
and exactly the same can be said with CSS, right ?
Link to comment
Share on other sites

jQuery is simply a program written with Javascript. jQuery makes accessing elements easier, but in the end it's just using Javascript's native HTML DOM methods which you could use yourself without jQuery if you wanted to.The style object is not programmed with Javascript, it's internal to the browser. You can't create a style object yourself with Javascript, you have to take it from the browser.

Link to comment
Share on other sites

CSS is a separate styling language. CSS can be manipulated with JavaScript.jQuery is just a bunch of functions written in JavaScript.

Link to comment
Share on other sites

jQuery is simply a program written with Javascript. jQuery makes accessing elements easier, but in the end it's just using Javascript's native HTML DOM methods which you could use yourself without jQuery if you wanted to.The style object is not programmed with Javascript, it's internal to the browser. You can't create a style object yourself with Javascript, you have to take it from the browser.
ahh yes, got it - it has to be defined (by CSS) before JS can "manipulate" it.
Link to comment
Share on other sites

You can use JavaScript to access the style property of any page element. No CSS has to be defined before doing this. Defining style rules in JavaScript is the same as adding/modifying a style attribute in an element's HTML tag.However, because the style property IS different from a CSS stylesheet, you cannot use it to read CSS stylesheet rules. You can set values at any time, and you can read the values that you have set. And if your tag does contain a style attribute, you can read those values also. But the style property does not get you access to stylesheet rules. There are ways to do that, but they are a little complicated.

Link to comment
Share on other sites

You can use JavaScript to access the style property of any page element. No CSS has to be defined before doing this. Defining style rules in JavaScript is the same as adding/modifying a style attribute in an element's HTML tag.
okay, i did a quick test to confim that, i had a <img> element with no style defined, not even width attribute, and i could change it's width via JS !(i thought that was an error in an earlier piece of code i made, i guess i must have "fixed" it by accident some other way.)
However, because the style property IS different from a CSS stylesheet, you cannot use it to read CSS stylesheet rules. You can set values at any time, and you can read the values that you have set. And if your tag does contain a style attribute, you can read those values also. But the style property does not get you access to stylesheet rules. There are ways to do that, but they are a little complicated.
i see, "advanced" CSS which i've not yet used to full advantage.am still only making single HTML files with mostly inline CSS, or at the "most" in the <head>.am starting a project which will have multiple HTML files though, that will be when i have to use CSS stylesheets proper.
Link to comment
Share on other sites

but really only sheet, right?
ahh, yes - with the right laxative... :)a nice clean purge in one go...
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...