Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change css position left to right using jquery?

Tags:

jquery

css

I have a div with left value i wanted to change it to right side with values

#check
{
    left:50px;
    top:20px;
    position:relative;
    width:100px;
    height:100px;
    background:rgb(100,200,0);
}

So i tried jquery like this

$(document).ready(function(){

    $('#check').css('right','20px');

});

is this possible?.i tried searching but all are with the same attribute different value changes. Here is the Fiddle

like image 622
sun Avatar asked Oct 04 '13 13:10

sun


People also ask

What does position() method do in jQuery?

jQuery position() Method The position() method returns the position (relative to its parent element) of the first matched element. This method returns an object with 2 properties; the top and left positions in pixels.

What is CSS manipulation in jQuery?

The jQuery CSS methods allow you to manipulate CSS class or style properties of DOM elements. Use the selector to get the reference of an element(s) and then call jQuery css methods to edit it. Important DOM manipulation methods: css(), addClass(), hasClass(), removeClass(), toggleClass() etc.

How to get position jQuery?

The . position() method allows us to retrieve the current position of an element (specifically its margin box) relative to the offset parent (specifically its padding box, which excludes margins and borders). Contrast this with . offset() , which retrieves the current position relative to the document.

What is offset in jQuery?

offset() returns an object containing the properties top and left . Note: jQuery does not support getting the offset coordinates of hidden elements or accounting for margins set on the <html> document element.


1 Answers

You have to set left to default, and the value for right:

$(document).ready(function(){

 $('#check').css({
  'right':'20px',
  'left': 'auto'
 });

});

JSfiddle thanks to MackieeE

like image 174
Mark Avatar answered Nov 15 '22 10:11

Mark