Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the following code I find no difference when I use the mouse over the button. What is wrong in the code?


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
$('.Button1').mouseover(function() {
$('.Panel1').hide();
});

$('.Button1').mouseout(function() {
$('.Panel1').show();
});
</script>
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<asp:Button ID="Button1" runat="server"
class="classnameL" Text="SUMIFS"
Width="100%" />
<asp:Panel ID="Panel1" runat="server" class="panel1" BackColor=Red BorderStyle=Groove BorderWidth=3 Height=33 Width=33/>


</form>
</body>
</html>
Posted

It's Because you are using wrong class for button. you are using class 'classnameL' in html for buttons but in jquery you use 'Button1'. i think you are trying to access button through id, if this is the case then use
JavaScript
$('#Button1').SomeThingYouWant
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 20-Mar-14 3:44am    
I tried like this:
$('#Button1').mouseover(function() {
$('.Panel1').hide();
});
$('#Button1').mouseout(function() {
$('.Panel1').show();
not working.
Hammad 20-Mar-14 3:47am    
as you have assigning id using asp.net 'ID' you can access it in jquery using
$('#<%=Button1.ClientID %>')
S.Rajendran from Coimbatore 20-Mar-14 3:51am    
$('#<%=Button1.ClientID %>').mouseover(function() {
$('.Panel1').hide();
});
$('#<%=Button1.ClientID %>').mouseout(function() {
$('.Panel1').show();
not working
Hammad 20-Mar-14 4:09am    
i prepared an example for you check it
http://jsfiddle.net/vq5rj/
S.Rajendran from Coimbatore 20-Mar-14 4:18am    
Thank you.
The problem lies in your jQuery code
1. Missing closing
</script>
in the jQuery library
2. Put your jQuery code in document.ready function so that they are effective only after the loading of the whole page
3. The names of the selectors should prefix with # since they are name as id in the body.
See the corrected jQuery code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#Panel1').hide();
    $('#Button1').mouseover(function () {
        $('#Panel1').hide();
    });

    $('#Button1').mouseout(function () {
        $('#Panel1').show();
    });
});
</script>
 
Share this answer
 
v2
Comments
S.Rajendran from Coimbatore 20-Mar-14 4:38am    
On page load the panel1 is visible which I dont want. Only when mouseover the button I want the Panel1 to visble. How to make it?
Peter Leow 20-Mar-14 4:55am    
Hide it when the document is ready, see edited solution. In this way, the first time Panel1 will only show after mouse over followed by mouse out.
S.Rajendran from Coimbatore 20-Mar-14 5:05am    
Thank you.
S.Rajendran from Coimbatore 20-Mar-14 7:53am    
While this code works with a separate page it is not in master page of my project. JQuery has no effect in master page. Panel1 displays on page load and mouseover mouseout has no effect. Please tell how to solve this.
Peter Leow 20-Mar-14 8:02am    
This was not mentioned in the original question. However, you can find out the solution from http://www.dotnetcurry.com/showarticle.aspx?ID=273

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