---
title: "jquery, my function is executed a lot of time instead of one"  
description: "jquery, my function is executed a lot of time instead of one"  
author: "Anonymous User"  
published: 2013-04-09  
updated: 2013-04-09  
canonical: https://www.mindstick.com/forum/741/jquery-my-function-is-executed-a-lot-of-time-instead-of-one  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# jquery, my function is executed a lot of time instead of one

Hi Everyone!\
when i'm clicking on .myClass I want 'a ' to appear before #[message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) unfortunately 'a a a a a' appear instead of it.\
My css are:\
#message{ width: 80%; height: 10%; border-[style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment):solid; border-width:5px;}\
\
.hideIt{ [visibility](https://www.mindstick.com/blog/301300/how-to-improve-your-visibility-in-zero-click-search-results):[hidden](https://www.mindstick.com/forum/2303/skip-validating-field-from-hidden-div);}and my code is:\
<div id="message">test1 <span [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="myClass hideIt">test2</span></div>\
<[script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) src="jquery.js"></script> <script> $([function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server)() {\
test = function() { $('#message').before('a '); }\
$([document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool)).on('mouseover', '#message', function () { var el = $(this); el2 = el.children('.myClass'); el2.removeClass('hideIt'); el2.on('[click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social)',test); el.on('mouseout', function() { el2.addClass('hideIt'); }); });\
}); </script>here a Fiddle link: http://jsfiddle.net/TDJVw/\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)! \

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!\
Your problem was that you was registering the click method each time the div was hovered. I moved the **click outside** of the **hover** method.


---

Original Source: https://www.mindstick.com/forum/741/jquery-my-function-is-executed-a-lot-of-time-instead-of-one

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
