My Sellerdeck Account | Free Trial

Sellerdeck Community and Knowledge Base

  #1  
Old 04-Jan-2018, 11:10 AM
MattSMR MattSMR is offline
Registered User
Join Date: Dec 2016
Full Name: Matt McCullough
Posts: 71
Thanks: 11
Thanked 16 Times in 12 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.
Reply With Quote
  #2  
Old Today, 11:53 AM
NormanRouxel's Avatar
NormanRouxel NormanRouxel is online now
Registered User
Join Date: Dec 2002
Full Name: Norman Rouxel
Posts: 10,795
Thanks: 9
Thanked 761 Times in 635 Posts
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 02:49 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.