-2

I don't know why, but when I try to set the position:fixed in jquery:

 $('#footer').css('cssText', 'position:fixed !important;');

for my footer, I get on the page this result:

 <div id="footer" style="position: static;">
    ...
 </div>

I've checked in the Chrome console and there is no css loaded a part this setted through code. For some circumstance I can't set this in the .css file.
why happean this?

Timo Güntner
  • 2,863
  • 4
  • 17
  • 24
Dillinger
  • 1,823
  • 4
  • 33
  • 78
  • No man, check here: http://stackoverflow.com/questions/2655925/how-to-apply-important-using-css – Dillinger Dec 01 '15 at 19:25
  • 1
    @Dillinger you should check this link: http://api.jquery.com/css/ – Dinei Dec 01 '15 at 19:26
  • I've already tried with this: $("#footer").css("position", "fixed"); and it's setted static – Dillinger Dec 01 '15 at 19:27
  • Yes, all of this as I said in the post. – Dillinger Dec 01 '15 at 19:28
  • Your question is unclear, it may be clear to you, but others are asking for clarification. Is the problem the fact that you can't override a CSS style defined inline as an HTML attribute? If so, that's how it works, inline styles are override any settings from a CSS file – Ruan Mendes Dec 01 '15 at 19:30
  • I also set other property through code and all working fine, but the problem's only when I set the fixed position – Dillinger Dec 01 '15 at 19:31

2 Answers2

0

That's not the way they do it, use this instead

$("#footer").css("position", "fixed");

And if this problem persists, try creating a class in css with position:fixed !important; like

.myClass{
       position:fixed !important;
 }

And add it to your footer using JQuery

$('#footer').addClass('myClass');
Collins Abitekaniza
  • 4,496
  • 2
  • 28
  • 43
0

Use this

$('#footer').css('position', 'fixed');

And consider where you are fixing it, with a top, left, right, or bottom css rule too.

irnmn
  • 726
  • 4
  • 20