How do I refresh the page on click if an element has exact text?
<p>I have a link that says 'Add to Favorites'. By default when you click this link and you are logged in, you get diverted to a confirmation page to say your favorite has been added. If you are not logged in it takes you to a login screen.</p>

<p>If you have already added that item to your favorites the text says 'Remove from Favorites' with an updated link to include '?A=Remove'. If you click it, you are redirected to a page confirming the favorite removal.</p>

<p>Now what I want to do is this:</p>

<p>If you're not logged in get an alert message.</p>

<p>If you are logged in - Refresh the page (Ideally I'd like to change 'Add to favorites' to 'Favorite added successfully' instead of refreshing the page - but I don't know how).</p>

<p>If you have already added to the favorites - Refresh the page (Ideally I'd like to change 'Remove from Favorites' to 'Favorite removed successfully' instead of refreshing the page - but I don't know how).</p>

<p>The {module_isloggedin} tag is generated by the system I am using. It generates a '1' if logged in &amp; '0' if not logged in.</p>

<p>So far all that happens is the error message - Perhaps because my :contains isn't working?</p>

<p>The whole code seems much too long and sloppy. I'm still learning :)</p>

<p>This is my jQuery so far, I haven't put in a page refresh for the 'remove from favorites' yet.</p>

<p>/** Updated code works, just a bit ugly :) **/</p>

<pre><code>jQuery('.add-favourites a').live('click', function(e){   
                    e.preventDefault();

        var loggedin = "{module_isloggedin}";

        if  (loggedin == 1) {
            var stringtocheckon = jQuery('.add-favourites a').html();

            if(stringtocheckon.indexOf('Add to Favorites')&gt;=0) {
                $.ajax({
                        url: $(this).attr('href'),
                        data: { 'A': 'Add' },
                        cache: false,
                        success: function (data) {
                            document.location.reload(true);
                        }
                    });

            }else{
                if(jQuery(this).attr('href').indexOf("A=Remove") != -1){
                    jQuery.ajax({
                        url: jQuery(this).attr('href'),
                        cache: false,
                        success: function (data) {
                            document.location.reload(true);
                        }
                    });
                }else{
                    jQuery.ajax({
                        url: jQuery(this).attr('href')+"&amp;A=Remove",
                        cache: false,
                        success: function (data) {
                            document.location.reload(true);
                        }
                    });
                }
    }
    }else{
        alert('You must be logged in to add favourites.');
    }
});
</code></pre>
