By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

adding class automation

P: 1
i need to add class to dynamically created span tags so that i can highlight it for some duration of time and then i need to remove it from this span and add class to other span tag.. In short u can say add class and remove class should continues based on time on each of the span tags..

example:
Expand|Select|Wrap|Line Numbers
  1. <span>some text1</span><span>some text2</span><span>some text3</span>
like this and i want text1 to be highlighted first and after few seconds second one should highlighted and so on..

Thanks in Advance
Anand kumar Singh
Jun 14 '13 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
what have you tried?
Jun 14 '13 #2

gits
Expert Mod 5K+
P: 5,298
a simple start would be like this:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <style type="text/css">
  3.         .hl {
  4.             color: red;
  5.         }
  6.     </style>
  7.     <script type="text/javascript">
  8.         function highlightNodes() {
  9.             var nodeBase = document.getElementsByTagName('SPAN');
  10.             var curNode = -1;
  11.  
  12.             for (var i = 0, n; n = nodeBase[i]; i++) {
  13.                 if (n.className == 'hl') {
  14.                     curNode = i;
  15.                     n.className = '';
  16.  
  17.                     if (curNode == nodeBase.length - 1) {
  18.                         curNode = -1;
  19.                     }
  20.                 }
  21.             }
  22.  
  23.             nodeBase[curNode + 1].className = 'hl';
  24.         }
  25.     </script>
  26.     <body onload="window.setInterval(highlightNodes, 1000);">
  27.         <span>some text1</span>
  28.         <span>some text2</span>
  29.         <span>some text3</span>
  30.     </body>
  31. </html>
  32.  
check it and try to understand it and adapt it to what u need. then come back with more specific questions.
Jun 14 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.