0

I want to do css !important so I use attr() like below. The problem is only the right work but not the top. At first I suspect in my other part of css there is an !important that override it, but there's none.

$('#submitted').attr({'style':'top: 0 !important', 'style':'right: 0 !important'});

I also tried like this, same problem occur, only right work. why?

$('#submitted').attr('style','top: 0 !important');
$('#submitted').attr('style','right: 0 !important');
user3522749
  • 309
  • 3
  • 10

2 Answers2

2

Because you're setting the style property twice. It's like saying:

style="foo";
style="bar";

since, as far as jquery is concerned, this is just a variable. It won't magically add ";" for you. On the other hand you can. Just do this:

$('#submitted').attr('style','top: 0 !important; right: 0 !important');
aquinas
  • 23,318
  • 5
  • 58
  • 81
0

Try using .css() as shown :

$('#submitted').css('top','0 !important');
$('#submitted').css('right','0 !important');
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69