Okay guys , so I have this algorithm that selects an option based on the keys that you press(up or down arrows).
var nr = 0;
$(function(){
$('#searchbox').keyup(function(e){
var total = $('#suggest'+nr).attr("total");
var code = (e.keyCode ? e.keyCode : e.which);
if ( up(code) == 1 )
{
if (nr == 0)
{
$('#suggest'+total).addClass('hlight');
}
}
else
if ( down(code) == 1 )
{
$('#suggest'+nr).css({'background':'red'});;
}
});
});
But the problem is that every time I release the respective div gets selected for like a fraction of a second by changing his background color and then get back to the original background color.
How do I make it highlight the div and the css to remain applied ?
Thank you.
HTML :
<div id="search">
<form action="home.php" method="get" name="search">
<input type="text" id="searchbox" name="srch" size="60" value="Search..." onFocus="if(this.value == 'Search...') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Search...';}" />
<input type='hidden' name='q' value='<?php echo $q; ?>' />
<input type='hidden' name='page' value='1' />
<button type="submit" id="searchb"><img src="pics/lens1.jpg" alt="Submit"></button>
</form>
</div><!--end search-->
PHP :
echo "<p class='suggestion' id=".$char." total=".($total-1)." style='color:black;font-size:13px;margin-bottom: 7px;'>".$id.",".$strg."</p>";
CSS:
<style >
.hlight{
background:yellow;
}
</style>
Take a look at the key functions here:
http://jsfiddle.net/Mutmatt/mQahU/
might help?