jquery Click Change Class and Toggle;jquery Click Change Image src Source and toggle;jquery Show hidden toggle

Source: Internet
Author: User

<meta charset= "Utf-8" >
<title></title>
<script type= "Text/javascript" src= "Http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js" ></script >
<style>
. bg1 {
Background-image:url (images/21.jpg);
Background-repeat:no-repeat;
Color: #0CF;
}
. Bg2 {
Background-image:url (images/22.jpg);
Background-repeat:no-repeat;
Color: #F00;
}
</style>
<script type= "Text/javascript" >
Parameter para1: ID value of the element you want to hide
function Toggle1 (PARA1) {
if ($ ("#p2"). attr ("class") = = "Bg1")
{
$ ("#p2"). attr ("Class", "Bg2");
}
Else
{
$ ("#p2"). attr ("Class", "bg1");
}
$ ("#" +PARA1). Toggle ();
}
</script>
<body>
<p id= "P1" > here to show or hide </p>
<p id= "P2" class= "bg1" onclick= "Toggle1 (' P1 ')" style= "height:31px" > click here to show or hide the above section and change your style (including background, font, etc.) </p >
</body>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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" onclick= "Toggle1 (' P1 ', ' img1 ')" 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" onclick= "Toggle1 (' P2 ', ' Img2 ')" 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>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>

<script src= "Http://code.jquery.com/jquery-1.11.1.min.js" ></script>
<script>
PARA1: ID of the element to hide
function Toggle1 (PARA1) {
JQuery ("#" +PARA1). Toggle ();
}
</script>

<body>
<p> Click Div1 to show or hide the div2</p> below
<div onclick= "Toggle1 (' Div2 ')" id= "Div1" >div1</div>
<!--here display defaults to none, if you have started to display, change to block---
<div id= "Div2" style= "Display:none" >div2</div>
</body>

jquery Click Change Class and Toggle;jquery Click Change Image src Source and toggle;jquery Show hidden toggle

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.