Mardoxx Posted August 1, 2009 Share Posted August 1, 2009 <html> <head> <style type="text/css"> body { font: 11px arial; } .deselected { background-color: #FFFFFF; padding: 2px 6px 2px 6px; } .selected { background-color: #FF6666; padding: 2px 6px 2px 6px; } .deselected_over { background-color: #3366CC; padding: 2px 6px 2px 6px; } .selected_over { background-color: #FF9999; padding: 2px 6px 2px 6px; } </style> <script language="javascript"> function hover(that) { var selected = true; var classes = { "deselected" : "deselected", "deselected_over" : "deselected_over", "selected" : "selected", "selected_over" : "selected_over"} if (that.className == classes['deselected']) { that.className = classes['deselected_over']; selected = false; } else { that.className = classes['selected_over']; } that.onmouseup = function() { that.className = (selected) ? classes['deselected_over'] : classes['selected_over']; selected = !selected; //just incase the user doesn't mouse out of the element } that.onmouseout = function() { that.className = (selected) ? classes['selected'] : classes['deselected']; } } </script> </head> <body> <div class="deselected" onmouseover="javascript:hover(this);">This is was originally deselected (white default, and blue on mouse over)</div> <br /> <br /> <br /> <div class="selected" onmouseover="javascript:hover(this);">This is was originally selected (deep red default, and light red on mouse over)</div> </body> </html> It highlights if clicked and calls mouseover events Link to comment https://forums.phpfreaks.com/topic/168417-a-challenge-sorten-this-code/ Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 Was there a question? Link to comment https://forums.phpfreaks.com/topic/168417-a-challenge-sorten-this-code/#findComment-888390 Share on other sites More sharing options...
Mardoxx Posted August 1, 2009 Author Share Posted August 1, 2009 yeah, I was wondering if there was an alternate (even shorter) way of doing that ^ Link to comment https://forums.phpfreaks.com/topic/168417-a-challenge-sorten-this-code/#findComment-888391 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 You could streamline the javascript if you used a library like jquery. You could also lose the javascript withing your html elements that way. Link to comment https://forums.phpfreaks.com/topic/168417-a-challenge-sorten-this-code/#findComment-888394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.