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
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With