Does JavaScript behave like CSS in that on-page scripts will take a higher precedence over external scripts? The reason I ask is because I am wondering if I can override an external script's commands to change a CSS attribute on expansion of a mobile nav bar.
Asked
Active
Viewed 617 times
1
-
Need more information. Do they set the method like `$('element').css('color', '#fff');` or does it happen through a bound event? `$('element').click(function(){ $(this).css('color', '#fff') });` or are you trying to over ride a variable? Please clarify – Ohgodwhy Nov 11 '13 at 23:16
-
The element has a class of position:fixed. For some reason the develooper removes this class when the navbar is expanded to show the nav links. I'd like to keep that fixed position. Just wondering if it's an 'easy fix' so that you don't have to alter someone else's code, or if that is so lazy as to be inelegant and stupid. – huzzah Nov 11 '13 at 23:19
1 Answers
4
You cannot really override anything that a previous script adds to a DOM element.
It will run, and then you just have to do something else to it.

Naftali
- 144,921
- 39
- 244
- 303
-
This is what I wondered about. So, you could be possibly seeing a flash of undesired behavior before YOUR script comes and does its thing. – huzzah Nov 11 '13 at 23:22
-
1@huzzah yep, that could and might happen. It is unavoidable unless you edit the original script. – Naftali Nov 11 '13 at 23:23
-
1@huzzah to minimize the undesires usually it comes to how speedy your machine is + the efficientcy of your code + the browser's engine. – Sir Nov 11 '13 at 23:26