2

I'm trying to add the padding-top value to the css that I append in the header , but only color is working:

        var PaddingTOp = $('#PaddingTOp').val();
        var PaddingRight = $('#PaddingRight').val();
        var PaddingBottom = $('#PaddingBottom').val();
        var PaddingLeft = $('#PaddingLeft').val();

        //Class Name
        $("<style type='text/css'> .redbold{ color:#f00; padding-top: PaddingTOp ;} </style>").appendTo("head");
        $(".container").addClass("redbold");
1
  • 5
    You are just setting the string PaddingTOp as the value and not the contents of that variable. Use concatenation. Commented Aug 20, 2015 at 13:34

2 Answers 2

2
$("<style type='text/css'> .redbold{ color:#f00; padding-top: "+PaddingTOp+" ;} </style>").appendTo("head");
Sign up to request clarification or add additional context in comments.

1 Comment

nice work , now i need all the other var if they have value will added to the line also .. i`m trying but the vars added without any values .!
0
    var PaddingTOp = $('#PaddingTOp').val();
    var PaddingRight = $('#PaddingRight').val();
    var PaddingBottom = $('#PaddingBottom').val();
    var PaddingLeft = $('#PaddingLeft').val();

    //Class Name

    var cssToApply = "color:#f00;";
    $.trim(PaddingTOp).length > 0 ?  cssToApply + "padding-top:"+PaddingTOp +";" : "";
    $.trim(PaddingRight ).length > 0 ?  cssToApply + "padding-right:"+PaddingRight +";" : "";
    $.trim(PaddingBottom ).length > 0 ?  cssToApply + "padding-bottom:"+PaddingBottom +";" : "";
    $.trim(PaddingLeft ).length > 0 ?  cssToApply + "padding-left:"+PaddingLeft +";" : "";

    $("<style type='text/css'> .redbold{ "+ cssToApply +"} </style>").appendTo("head");
    $(".container").addClass("redbold");

Comments

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.