Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click event failing on div in jQuery

I am using the below code:

<div class="business-bottom-content" onMouseOver="javascript:this.className='business-bottom-    content-hover';"  onMouseOut="javascript:this.className='business-bottom-content';"> 

The jQuery script is as following:

 $("div.business-bottom-content").click(
 function()
  {
   alert('ashutosh mishra');
  });
like image 791
Ashutosh Mishra Avatar asked Oct 04 '11 09:10

Ashutosh Mishra


1 Answers

You probably define the div after the script has executed.

Wrap it in $(document).ready(function() { .... }); to ensure it executes after the full DOM is available.

Additionally you should get rid of those ugly inline events (if you even need them - you can use :hover in CSS):

$('div.business-bottom-content').hover(function() {
    $(this).addClass('business-bottom-content-hover');
}, function() {
    $(this).removeClass('business-bottom-content-hover');
});
like image 141
ThiefMaster Avatar answered Oct 24 '22 08:10

ThiefMaster