Click event not working on div in jquery

I am using the code below

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

jquery script is as follows

  $("div.business-bottom-content").click( function() { alert('ashutosh mishra'); }); 
+6
source share
2 answers

You probably defined the div after executing the script.

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

In addition, you should get rid of these 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'); }); 
+19
source

You can try this for the div class to mention "."

  $(".business-bottom-content").click( function() { alert('ashutosh mishra'); }); 
+2
source

Source: https://habr.com/ru/post/898575/


All Articles