简体   繁体   English

发出淡出选择器的问题

[英]Issue fading out selector

I am trying to fade out a clicked ul element. 我正在尝试淡出单击的ul元素。 Here is the thing, I have multiple ul elements that contain the same class name for when selecting. 这是东西,我有多个ul元素,它们在选择时包含相同的类名。 To handle that I am phasing out a id for each specific ul to know which element to fade out. 为了解决这个问题,我正在逐步淘汰每个特定ulid ,以了解淡出哪个元素。 My issue is though, when trying to fade out the ul element. 我的问题是,当尝试淡出ul元素时。 Nothing happens at all, even though it contains the correct id . 即使它包含正确的id ,也不会发生任何事情。

Here is what I am doing: 这是我在做什么:

$(".start-dropdownClose").click(function(event){
       event.stopPropagation();
       $thisOne = $($(this).parent().parent().attr('id'));
       $($thisOne.selector).fadeOut();
});

When I alert the $thisOne.selector it displays the correct id of that selected ul element. 当我提醒$thisOne.selector它会显示所选ul元素的正确id I just don't know why it wont fade out though? 我只是不知道为什么它不会消失?

Suggestions, thoughts? 建议,想法?

Don't use its selector, just use the element object: 不要使用其选择器,只需使用element对象:

$(".start-dropdownClose").click(function(event){
   event.stopPropagation();
   $(this).parent().parent().fadeOut();
});

Try these two approaches: 尝试以下两种方法:

$(".start-dropdownClose").click(function(event){
       event.stopPropagation();
       $thisOne = $(this).parent().parent();
       $thisOne.fadeOut();
});

or 要么

$(".start-dropdownClose").click(function(event){
       event.stopPropagation();
       $thisOne = $($(this).parent().parent().attr('id'));
       $("#"+$thisOne).fadeOut();
});

The first one $thisOne is the ul you are trying to select and fadeout. 第一个$ thisOne是您要选择并淡出的ul。 So just fading it out should work. 因此,只要淡出效果就可以。

In the second approach, $thisOne is an id string, so to select it correctly with jQuery the correct syntaxis is $("#idString") 在第二种方法中,$ thisOne是一个id字符串,因此要使用jQuery正确选择它,正确的语法是$(“#idString”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM