jquery Click Toggle and change the image src

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">
http://www.w3.org/1999/xhtml">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>jquery Click Toggle and Change the icon src</title>
<script src= "Images/jquery-1.8.3.min.js" ></script>
<script>
function implementation
Parameter para1: ID of the element you want to hide
Parameter para2: ID of IMG that wants to change the image src
/*
function Toggle1 (PARA1,PARA2) {
if ($ ("#" +para2). attr ("src") = = "Images/col_24.jpg")
{
$ ("#" +para2). attr ("src", "images/col_11.jpg");
}
Else
{
$ ("#" +para2). attr ("src", "images/col_24.jpg");
}
$ ("#" +PARA1). Toggle ();
}
*/
jquery Closure Implementation
(function ($) {
$ (document). Ready (function () {
$ ("#div1"). Click (function () {
if ($ ("#img1"). attr ("src") = = "Images/col_24.jpg")
{
$ ("#img1"). attr ("src", "images/col_11.jpg");
}
Else
{
$ ("#img1"). attr ("src", "images/col_24.jpg");
}
$ ("#p1"). Toggle ();
});
$ ("#div2"). Click (function () {
if ($ ("#img2"). attr ("src") = = "Images/col_24.jpg")
{
$ ("#img2"). attr ("src", "images/col_11.jpg");
}
Else
{
$ ("#img2"). attr ("src", "images/col_24.jpg");
}
$ ("#p2"). Toggle ();
});
});
}) (JQuery);
</script>
<body>
<!--function to implement the HTML code section--
<!--
<div id= "Div1" style= "Width:350px;background-color: #0F3; height:30px; Vertical-align:middle; line-height:30px; " > Click here to hide the P1 below and change the icon src</div>
<p id= "P1" > P1</p> to Hide
<div id= "Div2" style= "Width:350px;background-color: #F00; height:30px; Vertical-align:middle; line-height:30px; " > Click here to hide the P2 below and change the icon src</div>
<p id= "P2" > P2</p> to Hide
-
<!--closures Implement the HTML code section--
<div id= "Div1" style= "Width:350px;background-color: #0F3; height:30px; Vertical-align:middle; line-height:30px; " > Click here to hide the P1 below and change the icon src</div>
<p id= "P1" > P1</p> to Hide
<div id= "Div2" style= "Width:350px;background-color: #F00; height:30px; Vertical-align:middle; line-height:30px; " > Click here to hide the P2 below and change the icon src</div>
<p id= "P2" > P2</p> to Hide
</body>

This article is from the "All the Way" blog, please be sure to keep this source http://cag2050.blog.51cto.com/1009647/1721873

jquery Click Toggle and change the image src

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.