1

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.

2
  • 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 Commented Nov 11, 2013 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. Commented Nov 11, 2013 at 23:19

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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 yep, that could and might happen. It is unavoidable unless you edit the original script.
@huzzah to minimize the undesires usually it comes to how speedy your machine is + the efficientcy of your code + the browser's engine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.