jQuery Toggle html characters +/-
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) — 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.
精彩评论