Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sat Nov 21, 2009 12:19 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ]  Bookmark and Share
Author Message
 Post subject: use mouseover to highlight selected words only
PostPosted: Wed Nov 19, 2008 6:02 am 
Offline

Joined: Sat May 26, 2007 10:06 am
Posts: 9
Hi
I have a big paragraph of text with a few selected words that I want to change color with "on mouse over", similar to a hyperlink.
But I want ALL the selected words to change when the mouse goes over any of them, not just the one.
can any one help thanks
A


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 10:35 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
Use the onmouseover event.

Alternatively, if you're stumped, show us where you're stumbled upon.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
 Post subject: use mouseover to highlight selected words only
PostPosted: Thu Nov 27, 2008 12:54 am 
Offline

Joined: Sat May 26, 2007 10:06 am
Posts: 9
Sorry even more confused now
i know i have to do:
onmouseover="style.color='#ffffff';"
onmouseout="style.color='#123456';"
to change one word wrapped in a <span>, but where do I put this and how does it change all the other words wrapped in seperate <span></span> tags?
can you give me more help?
thanks
A


Top
 Profile  
 
 Post subject: Re: use mouseover to highlight selected words only
PostPosted: Thu Nov 27, 2008 10:56 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
The inline event should be added on every element you want it to work.

Alternatively, we can add a script that would identify the span element of your desire.

I suggest give those span element a class name like:
Code:
<span class="special">
This will have the onmouseover and onmouseout event
</span>


The above code has a class name of special.

We can take advantage of that. First, have this stylesheet:
Code:
<style type="text/css">
.special{
color:#123456;}
.special:hover{
color:#fff;
}
</style>


..but that won't work well with IE.

You need Javascript:
Code:
<script type="text/javascript">
window.addEventListener?window.addEventListener('load',function()
   {
      ray.setSpecial('special'); // Pass the class name of the element
   },false):
window.attachEvent('onload',function()
   {
      ray.setSpecial('special'); // Pass the class name of the element
   }); // FF : IE
var ray=
{
setSpecial:function(clsNme)
   {
   var classEl = this.getClass(clsNme);
   for(var i=0;i<classEl.length;i++)
      {
      classEl[i].onmouseover=function()
         {
         this.style.color='#fff'; // Turn the color to white
         }
      classEl[i].onmouseout=function()
         {
         this.style.color='#123456'; // Turn the color to hexadecimal equivalent.
         }
      }
   },
getClass:function(classEl)
   {
      var els=document.getElementsByTagName('*'); // Get all elements
      var classArr = [] ; // Declare empty array
      var regExp = new RegExp('\\b'+classEl+'\\b'); // Class Element RegExp
      for(var i=0;i<els.length;i++)
         {
         if (regExp.test(els[i].className)) // If match on regExp
            classArr.push(els[i]); // Add into classArr array
         } // End of for loop
      return classArr; // Return the array;
   }
}
</script>


Hope that helps.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley