Jquery – String manipulation in jQuery

jquerystring

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 "-" 
else 
    replace "-" with "+"

Best Answer

Never mind, I figured it out

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

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