Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all I am working on jquery mouseleave event here I have ckeditor. I need to show ckeditor when I enter the mouse and need to fire when mouse leave here. I have done that.

When entered it's showing (first image) and in ckeditor writing some text and when applying some font (second image) it's firing means ckeditor will hide (third image). Fonts opening in some separate div I think but I need to fire it once mouse leaves the ckeditor div.

Plz check it once here is my code:

XML
<script type="text/javascript">
    $(document).ready(function () {

        $('#btndiv1').hide();

        $('#btndiv').hover(function () {
            $('#btndiv1').show();
        });
        });
</script>
<script type="text/javascript">
    $(document).ready(function () {
    var editor = CKEDITOR.editor.replace('editor1');
    $('#btndiv').mouseleave(function (event) {
        $('#btndiv1').hide("slow");
            alert(1);
            var value = editor.getData();
            alert(value);
            $('#btndiv').append(value);

        });
    });

       </script>



here my html code:


XML
<div id="btndiv" style="height:400px;width:800px; border:1px solid ">
    <div id="btndiv1" style="height:auto;width:auto; border: 1px solid  ;">
    <textarea  rows="10"   id="editor1"> </textarea>

        </div>
</div>



but I need to fire it when user completed designing his own text. How can i do this? Any help appreciated, thanks.
Posted

1 solution

Probably, what you observe accurately describes the behavior of your code, but it would take to much time to analyze it. Instead, better modify your code, it's wrong. First of all, you have two scripts both handling $(document).ready. Do it only once, and in one script. Also, if you want to handle .hover(), no need to write .mouseleave(). hover() already expects two handler methods, first for mouse in, second one for mouse out. Please see:
http://api.jquery.com/hover/[^].

Also, you should re-use the wrapper objects returned by selectors. If you calculate $("#btndiv") if finds some HTML DOM object by its attribute id="btndiv" and returns you a jQuerty wrapper for this element, you don't need to calculate it again and again — it takes considerable time and simply is not supportable (what if you change the id? going to change it in 3 other places?!).

It should be something like:
JavaScript
$(document).ready(function () {
    firstDiv = $("#btndiv1"); //use the wrapper later; bad id value; use some semantic values, no 1, 2...
    secondDiv = $("#btndiv"); //use the wrapper later
    firstDiv.hover(
        function () {
            //do something on mouse in
        }, 
        function () {
            //do something on mouse out
        }
    );
    //add other handlers, hide/show elements, change properties, etc...
});

Read more carefully:
http://docs.jquery.com/How_jQuery_Works[^],
http://api.jquery.com/category/selectors/[^].

Good luck,
—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900