Nafees Anwar
Nafees Anwar

Reputation: 6598

How to set border width with jQuery?

I have two variables like this

var X = 200,
    Y = 100;

and i want to set the boder-width of an element with jQuery according to these variables. I tried something like

$('someElement'),css('border-width','X Y')

$('someElement'),css('border-width',X Y)

$('someElement'),css({borderWidth: X Y})

but none of the methods is worked. Any help?

Upvotes: 1

Views: 4690

Answers (2)

Jasper Giscombe
Jasper Giscombe

Reputation: 313

 $('#someElement').css('border-width', X +'px'})

Upvotes: 0

Akshay
Akshay

Reputation: 14348

Try it like this i have added px and a space between X and Y

var X = 200,
    Y = 100;
$('div').css('border-width',X+'px '+Y+'px');
div{
    width:100px;
    height:100px;
    border-color:green;
    border-style:solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div></div>

Upvotes: 2

Related Questions