I have a fairly mundane piece jQuery that toggles a div's visibility when a + is clicked and hides it when a - is clicked (the + changes to a - when clicked). The problem is that the +/- toggler follows some text that sometimes has a + or - in it and both toggle. For instance: Find out more about blah-blah +. When clicked, the plus changes to a minus. When clicked again, both minuses change to pluses.
I thought if i just changed the + to a +
and a minus to a —
; in the jquery it would solve the problem, but it doesn't work. The div visibility toggles on/off but the plus/minus symbols don't change.
Here is the script:
function toggleSpecial(element)
{
jQuery(element).next(".hidden").slideToggle("fast");
jQuery(element).html(function(i,html) {
if (html.indexOf('+') != -1 ){
html = html.replace('+','-');
} else {
html = html.replace('-','+');
}
return html;
});
}
Here is the script with HTML codes replacing the + and - which doesn't work.
function toggleSpecial(element)
{
jQuery(element).next(".hidden").slideToggle("fast");
jQuery(element).html(function(i,html) {
if (html.indexOf('+') != -1 ){
html = html.replace('+','—');
} else {
html = html.replace('—','+');
}
return html;
});
}
Any ideas about what I am doing wrong or suggestions? Thanks!