Solved

jquery toggle effect

Posted on 2013-01-10
16
356 Views
Last Modified: 2013-01-10
im using jquery to make a toggle effet , like this

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>

    <style>
    
div.section
{
	margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: rgb(29, 113, 184);
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
}

div.section.green
{
		margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: #3aaa35;
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
	}


div.section a
{
	color: #FFFFFF;
	display: block;
	font-family: 'axure_handwritingregular';
	font-weight:normal;
	text-decoration: none;
}

    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div id='ViewCandidateInformationHeader' class="section">
        <a href="#" rel="toggle[ViewCandidateInformation]" data-openimage="images/collapse.png" data-closedimage="images/expand.png">
            Basic Details
            <img src="icons/Collapsed.png" border="0" id="imgCI" class="img-swap"/>
        </a>
        
        </div>
        <div id="ViewCandidateInformation">    
        <fieldset>
            <h1>
      
      
                asdasdsad</h1>
      
        </fieldset>
        </div>  
        
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
    
    </script>

        <script type="text/javascript" >

            // Applying SlideToggle effect on View Candidate Information Panel
            $("#imgCI").click(function() {
                $("#ViewCandidateInformation").slideToggle();
                if ($(this).attr("class") == "img-swap") {
                    this.src = this.src.replace("Collapsed", "Expanded");
                } else {
                    this.src = this.src.replace("Expanded", "Collapsed");
                }
                $("#ViewCandidateInformationHeader").toggleClass("green");
                $(this).toggleClass('clicked');
            });
          
        

     
        </script>
</body>
</html> 

Open in new window


i need to change it and want to hv click event on label1

plz help
0
Comment
Question by:panasonic2012
  • 8
  • 5
  • 3
16 Comments
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38762188
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38762190
TRY THIS - use html lable

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>

    <style>
    
div.section
{
	margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: rgb(29, 113, 184);
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
}

div.section.green
{
		margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: #3aaa35;
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
	}


div.section a
{
	color: #FFFFFF;
	display: block;
	font-family: 'axure_handwritingregular';
	font-weight:normal;
	text-decoration: none;
}

    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div id='ViewCandidateInformationHeader' class="section">
        <a href="#" rel="toggle[ViewCandidateInformation]" data-openimage="images/collapse.png" data-closedimage="images/expand.png">
            Basic Details
            <img src="icons/Collapsed.png" border="0" id="imgCI" class="img-swap"/>
        </a>
        
        </div>
        <div id="ViewCandidateInformation">    
        <fieldset>
            <h1>
      
      
                asdasdsad</h1>
      
        </fieldset>
        </div>  
        
        <Label ID="Label1"  runat="server" Text="Label" class="img-swap"> Label</Label>
    </div>
    </form>
    
    </script>

        <script type="text/javascript" >

            // Applying SlideToggle effect on View Candidate Information Panel
            $("#Label1").click(function() {
            alert("clicked")
                $("#ViewCandidateInformation").slideToggle();
               /* if ($(this).attr("class") == "img-swap") {
                    this.src = this.src.replace("Collapsed", "Expanded");
                } else {
                    this.src = this.src.replace("Expanded", "Collapsed");
                }*/
                $("#ViewCandidateInformationHeader").toggleClass("green");
                $(this).toggleClass('clicked');
            });
          
        

     
        </script>
</body>
</html>  

Open in new window

0
 

Author Comment

by:panasonic2012
ID: 38762286
i also need to change the image src , plz help me with that also , will be really appreciated
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38762291
You can find your image like
~/icons/Collapsed.png
0
 

Author Comment

by:panasonic2012
ID: 38762321
but what do i write in place of

 /* if ($(this).attr("class") == "img-swap") {
                    this.src = this.src.replace("Collapsed", "Expanded");
                } else {
                    this.src = this.src.replace("Expanded", "Collapsed");
                }*/

Open in new window

0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38762331
First take 2 variables in you function
var oldSrc = 'http://example.com/Collapsed.png';
var newSrc = 'http://example.com/expand.png';

To use

this.src = this.src.replace("oldSrc ", "newSrc");

I have not checked, whether it works or not.
But give a try
0
 

Author Comment

by:panasonic2012
ID: 38762340
no it didnt work , plz help
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38762372
try this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>

    <style>
    
div.section
{
	margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: rgb(29, 113, 184);
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
}

div.section.green
{
		margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: #3aaa35;
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
	}


div.section a
{
	color: #FFFFFF;
	display: block;
	font-family: 'axure_handwritingregular';
	font-weight:normal;
	text-decoration: none;
}

    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div id='ViewCandidateInformationHeader' class="section">
        <a href="#" rel="toggle[ViewCandidateInformation]" data-openimage="images/collapse.png" data-closedimage="images/expand.png">
            Basic Details
            <img src="icons/Collapsed.png" border="0" id="imgCI" class="img-swap"/>
        </a>
        
        </div>
        <div id="ViewCandidateInformation">    
        <fieldset>
            <h1>
      
      
                asdasdsad</h1>
      
        </fieldset>
        </div>  
        
        <Label ID="Label1"  runat="server" Text="Label" class="img-swap"> Label</Label>
    </div>
    </form>
    
    </script>

        <script type="text/javascript" >

            // Applying SlideToggle effect on View Candidate Information Panel
            $("#Label1").click(function() {
      
                $("#ViewCandidateInformation").slideToggle();
                
                if ($("#imgCI").attr("class") == "img-swap") {
                    $("#imgCI").attr("src" ,$("#imgCI").attr("src").replace("Collapsed", "Expanded"));
                } else {
                    $("#imgCI").attr("src",("#imgCI").attr("src").replace("Expanded", "Collapsed"));
                }
                $("#ViewCandidateInformationHeader").toggleClass("green");
                $(this).toggleClass('clicked');
            });
          
        

     
        </script>
</body>
</html>  

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:panasonic2012
ID: 38762394
the img doesnt change back on second click :(
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38762397
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>

    <style>
    
div.section
{
	margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: rgb(29, 113, 184);
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
}

div.section.green
{
		margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: #3aaa35;
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
	}


div.section a
{
	color: #FFFFFF;
	display: block;
	font-family: 'axure_handwritingregular';
	font-weight:normal;
	text-decoration: none;
}

    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div id='ViewCandidateInformationHeader' class="section">
        <a href="#" rel="toggle[ViewCandidateInformation]" data-openimage="images/collapse.png" data-closedimage="images/expand.png">
            Basic Details
            <img src="icons/Collapsed.png" border="0" id="imgCI" class="img-swap"/>
        </a>
        
        </div>
        <div id="ViewCandidateInformation">    
        <fieldset>
            <h1>
      
      
                asdasdsad</h1>
      
        </fieldset>
        </div>  
        
        <Label ID="Label1"  runat="server" Text="Label" class="img-swap"> Label</Label>
    </div>
    </form>
    
    </script>

        <script type="text/javascript" >

            // Applying SlideToggle effect on View Candidate Information Panel
            $("#Label1").click(function() {
      
                $("#ViewCandidateInformation").slideToggle();
                
                if ($("#imgCI").attr("class") == "img-swap") {
                    $("#imgCI").attr("src" ,$("#imgCI").attr("src").replace("Collapsed", "Expanded"));
                } else {
                    $("#imgCI").attr("src",$("#imgCI").attr("src").replace("Expanded", "Collapsed"));
                }
                $("#ViewCandidateInformationHeader").toggleClass("green");
                $(this).toggleClass('clicked');
            });
          
        

     
        </script>
</body>
</html>  

Open in new window

0
 

Author Comment

by:panasonic2012
ID: 38762404
still not changing , wat cud be the issue ?
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 38762455
try
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>

    <style>
    
div.section
{
	margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: rgb(29, 113, 184);
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
}

div.section.green
{
		margin: 0px;
	text-align: center;
	font-size: 18px;
	font-family: 'axure_handwritingregular';
	background-color: #3aaa35;
	padding: 2px;
	border-bottom: 2px solid rgb(63, 115, 188);
	}


div.section a
{
	color: #FFFFFF;
	display: block;
	font-family: 'axure_handwritingregular';
	font-weight:normal;
	text-decoration: none;
}

    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div id='ViewCandidateInformationHeader' class="section">
        <a href="#" rel="toggle[ViewCandidateInformation]" data-openimage="images/collapse.png" data-closedimage="images/expand.png">
            Basic Details
            <img src="icons/Collapsed.png" border="0" id="imgCI" class="img-swap"/>
        </a>
        
        </div>
        <div id="ViewCandidateInformation">    
        <fieldset>
            <h1>
      
      
                asdasdsad</h1>
      
        </fieldset>
        </div>  
        
        <Label ID="Label1"  runat="server" Text="Label" class="img-swap"> Label</Label>
    </div>
    </form>
    
    </script>

        <script type="text/javascript" >

            // Applying SlideToggle effect on View Candidate Information Panel
            $("#Label1").click(function() {
      
                $("#ViewCandidateInformation").slideToggle();
                
                if ($("#imgCI").attr("class") == "img-swap") {
                    $("#imgCI").attr("src" ,$("#imgCI").attr("src").replace("Collapsed", "Expanded"));
                } else {
                    $("#imgCI").attr("src",$("#imgCI").attr("src").replace("Expanded", "Collapsed"));
                }
                $("#ViewCandidateInformationHeader").toggleClass("green");
                $("#imgCI").toggleClass('clicked');
            });
          
        

     
        </script>
</body>
</html>  

Open in new window

0
 

Author Closing Comment

by:panasonic2012
ID: 38762459
works . sorry for being a noob
0
 

Author Comment

by:panasonic2012
ID: 38762470
cud u plz explain why wasnt it working before , i cant seem to find the difference , im learning
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38762491
we have not changed this line before

 $("#imgCI").toggleClass('clicked');
0
 

Author Comment

by:panasonic2012
ID: 38762493
yea , i just noticed that ... not really sure wat that line does though ...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now