Home > Web Front-end > JS Tutorial > body text

Detailed explanation of toggle replacement method in jQuery

黄舟
Release: 2017-06-26 13:37:29
Original
1462 people have browsed it

This article mainly introduces the relevant information of jQuery toggle alternative method. Friends who need it can refer to it

The specific content is as follows:

$('.back_left dt').toggle(function(){
$(this).addClass("selected");
$(this).siblings('dd').slideUp();
},function(){
$(this).removeClass("selected");
$(this).siblings('dd').slideDown();
});
Copy after login

Today in When I was working on a project, I copied a code from someone else's website and found that it couldn't be implemented. When I was so anxious that I didn't want to do it anymore, I thought, could it be a jquery version problem? Then I lowered the jquery version to 1.8 and the function was implemented. My own jqurey version is 1.11.1. It turned out to be a version problem. Once I found the reason, it was easy to solve. After searching on Baidu, I found that the toggle method was in version 1.9. It has beendeleted. Changing the version can solve the problem, but I don't want to use the lower version anymore. I still want to use the 1.11.1 version. What method can I use to replace toggle?

After testing, you can use the following method instead:

$(document).ready(function(){ 
$('.back_left dt').click(function(){
if($(this).hasClass("selected")){
$(this).toggleClass("selected");
$(this).siblings('dd').slideDown();
}else{
$(this).toggleClass("selected");
$(this).siblings('dd').slideUp();
} 
}); 
});
Copy after login
##ParametersDescription
speed Optional. Specifies how quickly an element goes from visible to hidden (or vice versa). Default is "0".

Possible values:

  • milliseconds (e.g. 1500)

  • "slow"

  • "normal"

  • "fast"

When the speed is set, during the process of the element going from visible to hidden, Will gradually change its height, width,

margins, padding, and transparency.

If this parameter is set, the switch parameter cannot be used.

callback

Optional. toggle FunctionThe function to be executed after execution.

To learn more about callbacks, visit our jQuery Callback chapter.

This parameter cannot be set unless the speed parameter is set.

switch ##Optional. Boolean value. Specifies whether toggle hides or shows all selected elements.

  • True - Show all elements

  • False - Hide all elements

If this parameter is set , the speed and callback parameters cannot be used.

The above is the detailed content of Detailed explanation of toggle replacement method in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template