Jump to content

Problem while using Javascript into HTML

- - - - -

  • Please log in to reply
4 replies to this topic

#1
MicroBoy

MicroBoy

    Newbie

  • Members
  • PipPip
  • 22 posts
I have a javascript function which I use in HTML, but how can I color just the "Shfaq Tekstin" text? Because there is a problem with quotes and if I use <font color="#000000">Shfaq Tekstin</font> It does not work, I think because of quotes? Is there any way to do it?

<span onclick="if (this.innerHTML != 'Shfaq Tekstin') { this.innerHTML = 'Shfaq Tekstin' } else { this.innerHTML = 'Fshih Tekstin<br />{TEXT}'}">Shfaq Tekstin</span>

p.s. All "Shfaq Tekstin" texts need to be Colored.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You can either use single quotes or escape your quotes, making each " into \" or ' into \' when they are contained within parent quotes from the onclick part.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
MicroBoy

MicroBoy

    Newbie

  • Members
  • PipPip
  • 22 posts
I tried both ways without success, if I use as above it is colored but javascript does not work, because of single quotes problem I think.

<span onclick="if (this.innerHTML != '<font color='#0000FF'>Shfaq Tekstin</font>') { this.innerHTML = '<font color='#0000FF'>Shfaq Tekstin</font>' } else { this.innerHTML = 'Fshih Tekstin<br />{TEXT}'}"><font color='#0000FF'>Shfaq Tekstin</font></span>


#4
oldhendra

oldhendra

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
Hi MicroBoy,
Does it have to be in 1 line?

Probably this would work...
<span class="green" onclick="if (this.textContent != 'Shfaq Tekstin') { this.textContent = 'Shfaq Tekstin'; this.className = 'red' } else { this.textContent = 'Fshih Tekstin<br />{TEXT}'; this.className = 'blue';}">Shfaq Tekstin</span>
But it has to be supported by a CSS:
<style type="text/css">
.red{
  color:red;
}
.blue{
  color:blue;
}
.green{
  color:green;
}
</style>
and incompatible with IE :c-thumbdown:
Use IE's node.innerText() instead of Mozilla's textContent() ?

Hendra

#5
MicroBoy

MicroBoy

    Newbie

  • Members
  • PipPip
  • 22 posts
Thnx a lot, I will try this, I found another way that is all different from this, but if this will work I will use it, thanks for your time.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users