开发者

jQuery Toggle html characters +/-

开发者 https://www.devze.com 2023-03-21 08:43 出处:网络
I\'m having a simple problem toggling between +/- characters which prepend a link which opens a dropdown menu. This code works, except I need to remove the div and just have the href toggle.

I'm having a simple problem toggling between +/- characters which prepend a link which opens a dropdown menu. This code works, except I need to remove the div and just have the href toggle.

Any help is appreciated.

HTML:

<a href="#" class="toggler"><span>+</span> toggle</a>
<div class="hidden">
 Hidden
</div>

jQuery:

$('a.toggler').click(function() {
        var $this = $(this);
        $this.next(".hidden").slideToggle("fast", function() {
        $this.find('span').text($(this).is(':visible') ? '-' : '+');
    });
});

I borrowed the code from this link: Need to replace +/- characters with html codes (for example) &#8212; in small piece o开发者_运维问答f jQuery


Here is an updated version:

http://jsfiddle.net/aGKJR/2/

I had it so it only toggled when you clicked the +/-. Now the whole link works.

Basically, you need to remove the slideToggle callback and place its code in the onclick function instead.


Your code works for me. There must be something wrong somewhere else your code. You should post it if you want more help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号