0

Actually I want something like that:

var color = #000;

$(".div").find("li").css({"border-left": '5px solid [`I want to add this variable (color) here`]});

Please help me.

Thank you.

3 Answers3

4

If you can use ES6 then a template literal is a good choice here. It uses backticks instead of other types of quotes.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

var color = "#000"; //change this to be a string as @Nikos mentioned

$(".div").find("li").css({"border-left": `5px solid  ${color}`});
WillD
  • 5,170
  • 6
  • 27
  • 56
1
$(".div").find("li").css({"border-left": `5px solid ${color}`});
robbieAreBest
  • 1,601
  • 14
  • 16
1

var color = "#00f";
$("#button").click(function(){
  $("div").css({"border": "5px solid " + color});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="button">Add Border</button>
<div>Hi, I am a div</div>
WoOHooW
  • 42
  • 1
  • 6