Home › Forums › Classic DFFS › Set CSS value on DispForm based on list item ID
- This topic has 3 replies, 2 voices, and was last updated 9 years ago by Alexander Bautz.
-
AuthorPosts
-
-
November 6, 2015 at 02:05 #9201
Hey again!
So we have a few specific articles in one of our lists that require specific formatting for tables when displayed. In doing some testing, I think I may be on the right track, but not quite there.
What I’m trying to do is make it so if the item ID is equal to ID’s 26, 30, or 31, that I inject the CSS via jQuery to format the table in those articles the way we wish. Here’s what I’ve managed to come up with, but it still doesn’t work. I’m not very experienced in JavaScript/jQuery so I’m likely missing something.
var itemID = "?ID=26"; $(function(){ if (location.search == itemID){ $(".ms-rteTableHeaderEvenCol-default, .ms-rteTableHeaderOddCol-default").css("color", "#FFF !important"); } });
Can anyone help me figure out what I’m missing?
Thanks!
- This topic was modified 9 years ago by Bloodlvst.
-
November 7, 2015 at 09:06 #9212
Hi,
You can put this in the Custom JS section in DFFS backend. It adds a style tag to the page with the override CSS code.var cssBuffer = []; switch(spjs.dffs.data.thisItemID){ case "26": cssBuffer.push(".ms-rteTableHeaderEvenCol-default, .ms-rteTableHeaderOddCol-default{") cssBuffer.push("color:#fff!important;"); cssBuffer.push("}"); break; case "30": // add the style like the previous "case" break; } $("body").append("<style type='text/css'>"+cssBuffer.join("")+"</style>");
Let me know how this works out.
Alexander
-
November 9, 2015 at 20:10 #9226
As always, thanks Alex!
This works exactly like I need it to! Now those 3 articles will have their special formatting when being displayed and still be easy to edit for our novice users 🙂
How much is a beer in Norway? I owe you several at this point.
-
November 9, 2015 at 23:18 #9231
I’m glad it worked out.
A good beer in the local grocery store is about $5 – so Norway is not the place you go for cheap beer!
Best regards,
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.