0

I want to change the CSS using jQuery if a certain statement returns true. I have been just playing around without the statement but it doesn't seem to work. This is my js file:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
window.SFW = window.SFW || {};
window.SFW.urgentAlertsItem = {
customItemHtml: function (ctx) {


    var urgentAlertsItemHtml = "<div class='urgent'><h2 class='name'>" + ctx.CurrentItem.Title + "</h2>";
    urgentAlertsItemHtml += "<div class='note'>" + ctx.CurrentItem.Note+ "</div>";
    urgentAlertsItemHtml += "<div class='severity'>" + ctx.CurrentItem.Severity+ "</div>";
    urgentAlertsItemHtml += "<div class='profile'> <img src='" + ctx.CurrentItem.Profile+"' /></div>";
    urgentAlertsItemHtml += "<button class ='moreDet'>More Detail</button></div>";
    return urgentAlertsItemHtml;
}
};

// anonymous self-executing function to setup JSLink templates on page load..
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};

overrideCtx.Templates.Header = "<div id='urg'>";
overrideCtx.Templates.Item = window.SFW.urgentAlertsItem.customItemHtml;
overrideCtx.Templates.Footer = "</div>";

overrideCtx.BaseViewID = 1;
overrideCtx.ListTemplateType = 100;

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();


// JavaScript source code
$(document).ready(function () {


        $(".severity").css("color: blue"); 

});

3 Answers 3

2

The correct syntax is either

$(".severity").css({"color" : "blue"});

OR

$(".severity").css("color", "blue");

The first syntax is used mostly to edit multiple css properties (separated by comma).

Source

0
1

This is the correct syntax

$(".severity").css("color", "blue");
0

You can always combine an if statement to check if a value is true before it executes the css color change.

if (statement) { //if the statement is true
     $(".severity").css("color", "blue");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.