-3

I'm use Font awesome icons in my vBulletin style and i want to change the (minus) icon to (plus) when click ! Is there a way to do it ?

    <a rel="nofollow" style="float:left" href="#" onclick="return
 toggle_collapse('forumbit_$forumid')">
 <span style="color:#24356C;" >
<i class="fa fa-minus-square-o fa-2x"></i>
</span>
</a>
pcs
  • 1,864
  • 4
  • 25
  • 49
WRONG WAY
  • 3
  • 3

2 Answers2

0

I think this question(and the answer) can help you do what you want :)

Change an element's class with JavaScript

Community
  • 1
  • 1
  • i have tried to do and i've succeeded, but when i clicked for one time the icon is changed from minus to plus icon , then remain plus until Reload the page again to return - but it works without problems here http://jsfiddle.net/WRONG_WAY/ub5jumo0/ – WRONG WAY May 17 '15 at 03:28
  • I am not sure why that would not work but I devised a little check in JSfiddle you may try: http://jsfiddle.net/ub5jumo0/5/ – DilyanYankov May 17 '15 at 12:36
-1

Assign an id to your icon, e.g.

<i class="fa fa-minus-square-o fa-2x" id="i-1"></i>

The id can be dynamic value like 'i-$forumid' depend on how you generate your html.

In your toggle_collapse('forumbit_$forumid') function, Add

var e = document.getElementById('i-1');
if (e.classList.contains('fa-plus-square-o')) {
  e.classList.toggle('fa-plus-square-o');
} else {
  e.classList.add('fa-plus-square-o');
}

or

function toggle_collapse(forumID) {
  ...

  var iconID = 'i-' + formumID.replace('forumbit_','')
  var e = document.getElementById(iconID);
  if (e.classList.contains('fa-plus-square-o')) {
    e.classList.toggle('fa-plus-square-o');
  } else {
    e.classList.add('fa-plus-square-o');
  }

  ...
}
Simon Lin
  • 29
  • 2