jquery and MVC 4.

show hide div using Knockoutjs jquery in mvc 4

Hello everyone,

I'm going to share the code sample of show hide div (content menu) using Knockoutjs and jquery in mvc 4.

I have a requirement to show the div onMouseOver and hide the div onMouseOut in Knockoutjs application.

Table of contents

1. show the div on-mouse-over from div.
2. hide the div on-mouse-out from div.

Here have two steps.
1. In the Step-1, code sample for view.
2. In the Step-2, code smple for viewModel.

Step-1 :   view 
code sample

    <ul data-bind="foreach: mDateTime">
        <li>
               <ul data-bind="foreach: $root.matter.index.type()[$data]">
                <li> 
                    <div id="hover" onmouseover="onMouseOver(this)" onmouseout="onMouseOut(this)">
                      <a href="#" ><img src="~/path.jpg" data-bind="text: matterId" /></a>
                    </div>
                        <div id="box" style="display: none">                       
                                <a href="#">Edit</a>
                                <a href="#">Copy</a>
                                <a href="#">Delete</a>
                         </div>                                 
                </li>
                <li data-bind="text: matterTitle"></li>
                <li data-bind="text: matterComment"></li>
            </ul>
        </li>
    </ul>

Step-2 : jQuery code sample


<script type="text/javascript">
    //Show the div onmouseover.
    function onMouseOver(obj) {
        var currentDiv = obj;
        var divToShow = $(currentDiv).next("#box");
        divToShow.toggle();
    }

    //Hide to div onmouseout
    function onMouseOut(obj) {
        //Todo:none
    }

</script>


ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book