Home>

I drip ancient style,Not much nonsense,Paste the code.

<html>
<head>
<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">
//param para1:the id value of the element i want to hide
function toggle1 (para1) {
  if ($("#p2"). attr ("class") == "bg1")
  {
    $("#p2"). attr ("class", "bg2");
  }
  else
  {
    $("#p2"). attr ("class", "bg1");
  }
  $("#" + para1) .toggle ();
}
</script>
</head>
<body>
<p>Here will show or hide</p>
<p onclick="toggle1 (" p1 ")">Click here to show or hide the upper part and change your style (including background image, font, etc.)</p>
</body>
</html>

jquery toggleclass () method

Examples

Toggle the "main" class for adding and removing all<p>elements:

$("button"). click (function () {
$("p"). toggleclass ("main");
});

Definition and usage

The toggleclass () method toggles one or more classes that add and remove selected elements.

This method checks the class specified in each element.Add class if it doesn't exist,If set, delete it.This is the so-called switching effect.

However, by using the "switch" parameter, you can specify that only classes are deleted or added.

grammar

$(selector) .toggleclass (classname, function (index, currentclass), switch)
  • Previous In-depth explanation of how to store application data in iOS development
  • Next Summary of various ways to get Date time in java