Results 1 to 2 of 2

Thread: jquery post load manipulation

  1. #1
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry jquery post load manipulation

    I'm currently using a script on an ecommerce website that shows or hide a free shipping stamp based on a number(price). Initially the stamp shows for all products and i hide it where necessary. My problem is, the script reads from the 'regular price' and will display the stamp accordingly, but i have products with promotions that hides the regular price and displays the promo price then bringing the actual price of the product under the appropriate limit and i can't figure out a way to hide the free shipping stamp on those particular items.

    I'm using the following to remove the tag if the price goes under 99, but with my hackish promotion price display, i cant figure out how to read that post load promo price display to apply the function as needed. I've tried replicating this script and applying it to the promo price div to no avail. Any suggestions as to how i can read a divs numerical contents post load and hide the stamp? I'm beginner to intermediate when it comes to jquery so help in layman's terms would be helpful.

    HTML Code:
        $('#results-table .redprice, #pp-wrap #big-price span').each(function(){
    	var $this = jQuery(this);
    	var number=$this.html();
    	number=number.substring(1);
    	number=parseFloat(number);
    		if(number > 50){$this.parents('div.grid3wrapper, div.list3wrapper, #pp-wrap').addClass('over50');}
    		if(number > 99){$this.parents('div.grid3wrapper, div.list3wrapper, #pp-wrap').addClass('over99');}
    		if(number < 99){$this.parents('div.grid3wrapper, div.list3wrapper, #pp-wrap').addClass('under99').removeClass('freeshipping');}
        });
    Thank you.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Are you asking how to run the above code after the promo price appears? If so, and assuming that code works, it would probably be best to have the above code as a function, ex:

    Code:
    function check4freeshipping(){
        $('#results-table .redprice, #pp-wrap #big-price span').each(function(){
    	var $this = jQuery(this);
    	var number=$this.html();
    	number=number.substring(1);
    	number=parseFloat(number);
    		if(number > 50){$this.parents('div.grid3wrapper, div.list3wrapper, #pp-wrap').addClass('over50');}
    		if(number > 99){$this.parents('div.grid3wrapper, div.list3wrapper, #pp-wrap').addClass('over99');}
    		if(number < 99){$this.parents('div.grid3wrapper, div.list3wrapper, #pp-wrap').addClass('under99').removeClass('freeshipping');}
        });
    }
    Then, whenever the prices are set, run the check4freeshipping function.

    All that remains to be determined is, when are the prices set? If it's - say on load of the page, you could do:

    Code:
    jQuery(window).load(check4freeshipping);
    If it's at some other time and is synchronous, you could just do it right after the price is set, ex:

    Code:
    //code here that sets the prices
    check4freeshipping();
    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. IE issue for jquery load
    By letom in forum JavaScript
    Replies: 12
    Last Post: 04-26-2013, 07:40 PM
  2. Using jQuery to load menu
    By nonagon in forum JavaScript
    Replies: 4
    Last Post: 04-19-2012, 02:30 PM
  3. jquery .load
    By ggalan in forum JavaScript
    Replies: 8
    Last Post: 09-03-2010, 06:34 PM
  4. jQuery JS Load in a Div Help
    By takuhii in forum JavaScript
    Replies: 3
    Last Post: 01-17-2009, 11:38 PM
  5. Image manipulation php/ajax/jquery script?
    By acctman in forum Looking for such a script or service
    Replies: 2
    Last Post: 08-19-2008, 12:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •