Announcement

Collapse
No announcement yet.

Jquery update style of span

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Jquery update style of span

    We have an external javascript file (actinicsearch.js) that gets called as part of a catalog results page, AJAX is involved on this document - https://www.columnradiators4u.co.uk/...radiators.html

    I have a jquery function for altering colour of a span when it detects certain text - please see my code below.

    Code:
    function ReInitStockColor(){
     $(function() {
      $("span:contains(In Stock)").css("font-weight", "bold").css("color", "#00BF00");
      $("span:contains(Due)").css("color", "#FF0000");
      $("span:contains(Made)").css("font-weight", "bold").css("color", "#00BF00");
     });
    }
    This code is being called earlier on in our file, however it is not executing. If I take my code in to chrome/Firefox console and run it, it executes successfully.

    Is anybody able to assist in this matter?

    Many thanks in advance,

    Matt - SMR.

    EDIT: Should probably add, see my last post of this thread - reason behind this method. http://community.sellerdeck.com/showthread.php?t=57439
    Matt. M - SMR Enterprises Ltd.

    #2
    You have some serious filtering going on so a lot of the page content is being loaded via AJAX. You'll need to run this code after the page reloads.

    Luckily function HideLoadingDialog (in actinicsearch.js) is called whenever the AJAX finishes so you could put the call to your code there.

    Or (so you don't have to patch SD code and to have no problems if SD updates HideLoadingDialog in the future), you could extend HideLoadingDialog as follows:
    Code:
    function ReInitStockColor(){
     $(function() {
      $("span:contains(In Stock)").css("font-weight", "bold").css("color", "#00BF00");
      $("span:contains(Due)").css("color", "#FF0000");
      $("span:contains(Made)").css("font-weight", "bold").css("color", "#00BF00");
     });
    }
    
    (function (w){	// define a closure and pass in a reference to the global window object
    	var HideLoadingDialogOld = w.HideLoadingDialog;		// save SD function;
    	w.HideLoadingDialog = function (t){			// redefine SD function
    	HideLoadingDialogOld.apply(this, [t]);			//  to execute old SD function
    	ReInitStockColor();					//   and now execute our own code
    	}
    })(window || {})
    And place the above code anywhere after actinicsearch.js is loaded.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment

    Working...
    X