Jquery – String manipulation in jQuery


I have a div which collapses clicking on a text header. I want to change the header from "+ filters" to "- filters" accordingly (when the div is collapsed or expanded)

How can I perform this with jQuery?

if (headerDiv.text() starts with "+")
    replace "+" with "-" 
    replace "-" with "+"

Best Answer

Never mind, I figured it out

if ($(header).text().trim().charAt(0) == "+")
    $(header).text($(header).text().replace("+", "-"));
    $(header).text($(header).text().replace("-", "+"));

If this is not the correct way, I'd appreciate a heads up