forum

Home / DeveloperSection / Forums / jquery, my function is executed a lot of time instead of one

jquery, my function is executed a lot of time instead of one

Anonymous User179009-Apr-2013
Hi Everyone!

when i'm clicking on .myClass I want 'a ' to appear before #message unfortunately 'a a a a a' appear instead of it.

My css are:

    #message{
    width: 80%;
    height: 10%;
    border-style:solid;
    border-width:5px;
}


 .hideIt{
    visibility:hidden;
}
and my code is:

<div id="message">test1 <span class="myClass hideIt">test2</span></div>

    <script src="jquery.js"></script>
    <script>
    $(function() {

        test = function() { $('#message').before('a '); }

        $(document).on('mouseover', '#message', function () {
            var el = $(this);
            el2 = el.children('.myClass');
            el2.removeClass('hideIt');
            el2.on('click',test);
            el.on('mouseout', function() {
                el2.addClass('hideIt');
            });
        });

    });
    </script>
here a Fiddle link: http://jsfiddle.net/TDJVw/

Thanks in advance! 


Updated on 09-Apr-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By