www.webdeveloper.com
Results 1 to 5 of 5

Thread: Change a table row bgcolor onBlur

  1. #1
    Join Date
    Sep 2005
    Posts
    2

    Question Change a table row bgcolor onBlur

    Is there any way to modify the bgcolor of a table row using javascript and possibly css when a control in that TR looses focus?

    Thanks!

  2. #2
    Join Date
    Jul 2005
    Location
    USA
    Posts
    912
    What kind of controls are you talking about in the TR?

  3. #3
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Code:
    <script type="text/javascript">
    if (document.getElementsByTagName) onload = function () {
    	var e, i = 0
    	while (e = document.getElementsByTagName ('TD')[i++]) {
    		e.parentNode.className = 'blurred'
    		e.onblur = function () {this.parentNode.className = 'blurred'}
    		e.onfocus = function () {this.parentNode.className = 'focused'}
    	}
    }
    </script>
    
    <style type="text/css">
    tr.blurred, tr.blurred th, tr.blurred td {
    	background-color:#aaa;
    	color:#555;
    }
    </style>
    
    <table summary="">
    	<thead>
    		<tr>
    			<th scope="col">Heading</th>
    			<th scope="col">Heading</th>
    		</tr>
    	</thead>
    	<tbody>
    		<tr>
    			<td>Data</td>
    			<td>Data</td>
    		</tr>
    		<tr>
    			<td>Data</td>
    			<td>Data</td>
    		</tr>
    	</tbody>
    </table>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  4. #4
    Join Date
    Sep 2005
    Posts
    2
    Thanks that should work. What JS version was the className property implemented in?

  5. #5
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Quote Originally Posted by xcervera
    What JS version was the className property implemented in?
    W3C DOM level 1. See http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/ .
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles