Reputation: 192
<div><a id="link" style="position:fixed !important;
bottom:0px !important;
right:0px !important;
color:#000000 !important;font:10pt Arial !important">press me</a>
</div>
In order to change that div block into
<div><a id="link" style="position:fixed !important;
bottom:0px !important;
left:100px !important;
color:#000 !important;font:10pt Arial !important">press me</a>
</div>
(only the left property is different), I try this
($'#link').RemoveAttr('style');
Upvotes: 0
Views: 229
Reputation: 55750
It is a bad practice to use Inline styles..Also you need to avoid using !important as well..
Use classes instead of inline styles..
That looks lot cleaner
HTML
<div>
<a id="link" class="link right" >press me</a>
</div>
CSS
.link
{
position:fixed !important;
bottom:0px !important;
color:#000000 !important;
font:10pt Arial !important;
}
.right
{
right:0px !important;
}
.left
{
left:100px !important;
}
Javascript
Then you can just use .addClass()
and .removeClass()
to get the things done..
$('#link').on('click', function() {
$(this).removeClass('right').addClass('left');
});
Upvotes: 1
Reputation: 630
the .css()
method relates to inline styling as you have above rather than the .attr()
method, so if the left
property is all you wish to change, try:
$('#link').css({ 'right' : 'auto', 'left' : '100px' });
Upvotes: 1
Reputation: 2122
You can use .attr('style', '') to remove, and .attr('style', '...'); to set the style back.
But it might be better to set the css styles to two different classes and use .addClass() and .removeClass() instead.
Upvotes: 6
Reputation: 502
you could do it this way one by one:
$('#elementID').css('property','value');
or you could write some style properties on your css file like:
.tobeadded{
positon:relative;
...
...
}
and then you could add this class to that element:
$('#elementID').addClass('tobeadded');
Upvotes: 0