5 Replies - 819 Views - Last Post: 11 July 2010 - 11:10 PM

#1 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 513
  • Joined: 21-December 08

change font color

Posted 10 July 2010 - 10:45 AM

I have this problem. When an ahref is clicked on a certain function is called. This function is called select_cresc(). The function works only on the else branch.
When the Pret crescator a href is white it should be made grey when clicked on, but it does not work. How can this function only work on the else branch and not on the if branch, I just cannot figure it out.

function select_cresc()
{
if (document.getElementById('cresc').style.color=="White") 
		{	
		document.getElementById('cresc').style.color="#84915D";
		pret="";
		
		}
else {
	  document.getElementById('cresc').style.color="White";
	  document.getElementById('descresc').style.color="#84915D";
	  pret="cresc";	
	  }
}





<li><a href="#"  onclick="select_cresc()><div id="cresc">Pret crescator</div></a></li>




So when i clicked the ahref once it sould be made white. When i click it again it should be made gray again. This last part does not work.

Is This A Good Question/Topic? 0
  • +

Replies To: change font color

#2 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: change font color

Posted 10 July 2010 - 10:56 AM

<li><a href="#"  onclick="select_cresc()><div id="cresc">Pret crescator</div></a></li>


This won't work - it's missing a closing quote for the onclick attribute.
Otherwise I can't see anything wrong with the JS, though your naming convention makes it very confusing for such a small snippet!

Also, for futureproofiness and stuff, you shouldn't put divs inside anchors.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,607
  • Joined: 08-June 10

Re: change font color

Posted 10 July 2010 - 12:01 PM

View Postmoopet, on 10 July 2010 - 05:56 PM, said:

Also, for futureproofiness and stuff, you shouldn't put divs inside anchors.

futureproofness? it is explicitly forbidden by the HTML rules to place block elements inside inline elements.

This post has been edited by Dormilich: 10 July 2010 - 12:02 PM

Was This Post Helpful? 1
  • +
  • -

#4 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: change font color

Posted 10 July 2010 - 03:36 PM

View PostDormilich, on 10 July 2010 - 06:01 PM, said:

View Postmoopet, on 10 July 2010 - 05:56 PM, said:

Also, for futureproofiness and stuff, you shouldn't put divs inside anchors.

futureproofness? it is explicitly forbidden by the HTML rules to place block elements inside inline elements.


Well, yes, I probably should have used a different sequence of words there. Well spotted, I was just testing, etc.
Was This Post Helpful? 0
  • +
  • -

#5 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 513
  • Joined: 21-December 08

Re: change font color

Posted 11 July 2010 - 08:41 AM

IT'S NOT THE QUOTE. I still have the same problem.
Man, so many problems for such an easy thing.
I'm sick and tired of all this.
It's better to read a book.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,607
  • Joined: 08-June 10

Re: change font color

Posted 11 July 2010 - 11:10 PM

do you have a test page?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1