Add ajax to a simple jquery function

I am using some simple jquery to show view cart button if something has been added to the cart.

if ( $('.cartSummaryItem').text() != 'Shopping cart is empty.' ) {

If the cart is empty it show this the text "Shopping cart is empty.", if something is added .account will fadeIn. The problem is I need to refresh the page for this to work, is there a way to do this without refreshing the page with ajax or similar?

Thanks Nik


If the change event doesn't work. Another method is using an Interval.

<script type='text/javascript'>
        setInterval(function () { 
            if ( $('.cartSummaryItem').text() != 'Shopping cart is empty.' ) {
        }, 10000);

Ofcourse, the interval should be changed to your desired amount. I would only use this if the change doesn't work.. The change event is prefered.

Need Your Help

JQuery post not working on dynamic jQuery elements

php javascript jquery html ajax

NOTE: This question is a split from the post: jQuery not working on elements created by jQuery

How to make smth after AJAX call?

javascript jquery ajax callback

I have an ajax call which returns a string and creates a &lt;span&gt; element with a string in it. Then I want to add some class to a newly created span. But due to asynchronous nature of AJAX, fun...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.