in jquery, how do I add an 'onmouseover' event to an element.
eg
<tr id=row bgcolor=white>
becomes
<tr id=row bgcolor=white onMouseOver="this.bgColor='red'">
You could use the attr
method:
$('#row').attr("onMouseOver", "this.bgColor='red'")
But since you are using jQuery I'd recommend using the on
method:
$('#row').on('mouseover', function() {
$(this).css('background-color', 'red');
});
try this if the element is static:
var $row = $('#row');
$row.mouseover(function(){
$row.css('background-color','red');
});
use this if the element is dynamically placed in the page:
var $row = $('#row');
$row.on('mouseover',function(){
$row.css('background-color','red');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With