/    Sign up×
Community /Pin to ProfileBookmark

javascript question.

hello.. im new in javascript.. just started learning actually.. i know the basics and i have a question..

why doesnt this work?

[CODE]<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<p id=”demo” style=”color:#000000;”>
JavaScript can change the style of an HTML element.
</p>

<script>
function myFunction()
{
x=document.getElementById(‘demo’) // Find the element
if (x.style.match(“ff”))
{
x.style=”color:#000000″;
}
else
{
x.style=”color:#ff0000″; // Change the style
}
}
</script>
<button type=”button” onclick=”myFunction()”>Click Me!</button>

</body>
</html>

[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsDec 08.2012 — [CODE] <!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<p id="demo" style="color:#000000;">
JavaScript can change the style of an HTML element.
</p>

<script>
function myFunction()
{
x=document.getElementById('demo') // Find the element
if (x.style.color.match("ff")||x.style.color.match("255")){ // Moz browsers use RGB 'rgb(255,0,0) == red
x.style.color='#000000';
}
else
{
x.style.color='#ff0000'; // Change the style
}
}
</script>
<button type="button" onclick="myFunction()">Click Me!</button>

</body>
</html>

Quick reply to this message Reply Reply With Quote Reply With Quote Multi-Quote This Message

[/CODE]
Copy linkTweet thisAlerts:
@telisjokauthorDec 08.2012 — ohhh i now get it... so my code was correct.. i just didnt know about the moz issue

thank you very much
Copy linkTweet thisAlerts:
@vwphillipsDec 08.2012 — see also

x.style.color='#000000';
Copy linkTweet thisAlerts:
@Logic_AliDec 08.2012 — ohhh i now get it... so my code was correct.. i just didnt know about the moz issue

[/QUOTE]
Your code was not correct because it was asking the wrong question:[CODE]if (x.style.match("ff"))[/CODE][/QUOTE]
×

Success!

Help @telisjok spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...