Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery to change style attribute of a div class

I have a slider class like this and I wan to change the style attribute style="left: 336px"

<div id="range-cont"> <div class="slider"> <div class="progress" style="width: 350px;"></div>     <a class="handle" href="#" **style="left: 336px;"**></a> </div> <input id="percentage" class="range" type="range" value="14" name="percentage" min="0" max="100"> <p id="percent-label">%</p> </div> </div> 

I tried $('.handle').css({'style':'left: 300px'}) but its not working. Not sure what I am doing wrong here

like image 688
Anurag Sharma Avatar asked Oct 25 '13 05:10

Anurag Sharma


2 Answers

Just try $('.handle').css('left', '300px');

like image 66
Ganesh D Avatar answered Sep 21 '22 15:09

Ganesh D


if you just want to set the style attribute use

$('.handle').attr('style','left: 300px'); 

Or you can use css method of jQuery to set only one css style property

$('.handle').css('left', '300px'); 

OR same as key value

$('.handle').css({'left': '300px', position}); 

More info on W3schools

like image 41
The Code Avatar answered Sep 21 '22 15:09

The Code