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(); });
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(); } }); });
Description | |
---|---|
speed | Optional. Specifies how quickly an element goes from visible to hidden (or vice versa). Default is "0". Possible values:
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.
|
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!