__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Last edited by AndrewGSW; 12-04-2012 at 10:14 PM..
In CSS, you use a period (.) to indicate "match on class name" and the octothorp (#) to indicate "match on id".
So:
Code:
<html>
<head>
<style type="text/css">
.funky {
color : magenta;
background-color : lime;
}
#butNotMe {
color : black;
backgroundColor : white;
}
</style>
</head>
<body>
<div class="funky" id="woof">This text will show purple on green</div>
<div class="funky" id="butNotMe">This text will be black on white</div>
<div class="funky" id="zing">Back to purple on green</div>
</body>
</html>
How did you get started in JavaScript, mucking with things like canvas and more, and completely bypass the fundamentals of HTML and CSS??
I think it would be worth your while to go back and catch up on HTML and CSS.
Oh, and by the way, this question has nothing to do with JavaScript.
(Though jQuery uses "." and "#" in the same way as "selectors".)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Oh, and the stuff with $ is *LIKELY* jQuery. A JavaScript library.
In jQuery, you use
Code:
$("#butNotMe")
as a shorthand for
Code:
document.getElementById("butNotMe")
By and of itself, that's not a huge advantage.
But jQuery also allows you to use
Code:
$(".funky")
as a short hand for
Code:
document.getElementsByClassName("funky")
and then IN EITHER CASE allows you to write code that affects *ALL* the elements found (whether only one when "#" is used of hundreds when "." is used).
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Hey, octothorp/octothorpe/octotherp was around for many many years before programmers ever started calling it the "hash symbol". It never had been in usage in the USA before you Brits started calling it that.
It was actually called the "pound sign" when I was a kid, meaning weight in pounds (you know, those things you Brits invented, foisted off on us, and then abandoned!). That is, we used to commonly write 37# (pr sometimes #37) meaning 16.8kg.
So far as I am concerned, JavaScript is useless without completely understanding HTML and CSS. You will keep on asking questions like this because even JavaScript programmers *NEED* to know how the underlying HTML and CSS work to be effective. You are running around with blinders on (or that another Americanism?) if you fail to learn HTML and CSS.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
What could you even do without HTML and CSS in javascript? I thought the whole point of it was to manipulate HTML elements and their styles. AS far as I know that is.