Replacing Text in a Toggled Anchor with JQuery

Posted by willmcneilly on Stack Overflow See other posts from Stack Overflow or by willmcneilly
Published on 2010-05-14T11:01:44Z Indexed on 2010/05/14 11:04 UTC
Read the original article Hit count: 155

Filed under:
|
|

Hi

I'm trying to change the text in an anchor on toggle. I'm doing this way at the moment but have found that once the anchor markup has replaced the toggle no longer works. Can someone please explain why this is happening and a solution? Many thanks.

    $('a#toggleHeader').toggle(function() {
    $('#header-wrapper').slideUp();
    $(this).replaceWith('< href=\"#\" id="toggleHeader">Show Header</>');

//Note:I've move the anchor because I can only post one anchor as a new user

},function(){
    $('#header-wrapper').slideDown();
    $(this).replaceWith('<a href=\"#\" id="toggleHeader">Hide Header</a>');

});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about toggle