Does JavaScript have an order of precedence like CSS? [duplicate] - javascript

This question already has answers here:
load and execute order of scripts
(6 answers)
Closed 9 years ago.
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.

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.

Related

Why would a <script> tag contains HTML comments in it? [duplicate]

This question already has answers here:
Are HTML comments inside script tags a best practice? [closed]
(10 answers)
Closed 2 years ago.
In this app I'm working on I see this pattern a lot:
<script type="text/javascript">
<!--
doStuff();
//-->
</script>
What purpose might those comment tags serve? Can I safely remove them?
In ancient times some browsers didn’t understand the <script> tag so it was made in a way that you can add comments to the beginning without issues. This causes anything inside to not be shown on the page if the browser doesn’t know what to do with the tag.
This hasn’t been needed in a very long time so it’s safe to remove them.

Can a block enable loading of css/js? [duplicate]

This question already has an answer here:
How to attach js/css to a StreamField block when it is rendered?
(1 answer)
Closed 4 years ago.
I want to create a block that is going to utlize some js/css from a CDN, and possibly some custom js code just before the </body>. I do not want these loaded unless the block is used on the current page. Is there a way I can check if the block has been used, or even better, have the block tell the base.html file that it is being used?
If you already have jQuery in your project, the easiest way to do this will be with getScript. Documentation is here: https://api.jquery.com/jquery.getscript/
With plain JS, you have to jump through slightly more hoops and create a <script> tag that you then append to the document:
var dynamically_loaded_js = document.createElement('script');
dynamically_loaded_js.setAttribute('src','http://example.com/dynamically_loaded.js');
document.body.appendChild(dynamically_loaded_js);

Does order of attributes matter in script tags? [duplicate]

This question already has answers here:
Does the order of HTML attributes have any effect on performance?
(2 answers)
valid order for attributes of input type tag
(5 answers)
Closed 8 years ago.
I have a WordPress plugin that enqueues a Javascript file. This is the current format:
<script src='http://www.mywebsite.com/myscript.js' data-cfasync='false'></script>
The 'data-cfasync' attribute is to instruct CloudFlare Rocket Loader to ignore the script, per their KB.
However, CloudFlare's URL format is like this:
<script data-cfasync="false" src="/javascript.js"></script>
Notice the data-cfasync attribute is before the src attribute. Does that make a difference? Does the order of attributes matter?
The order of attributes in HTML elements doesn't matter. You can write the attributes in any order you like id last onclick first - it does not matter.

how to write css for inner html of iframe [duplicate]

This question already has answers here:
How to apply CSS to iframe?
(28 answers)
Closed 8 years ago.
have one question, i trapped in a prob..The problem is like that --->I have to manipulate the css of inner html of iframe but the content of this iframe is not coming from same domain so how can it makes possible
live eg.-u can take ("tweets feed in our website ,it comes from another domain tweeter.com/bla....blaa but render on our web page encapsulate with iframe,so how can i style tweet section in our website")
i have tried by jQuery but its not working can u plz help me out in that ?
Thanks in advance Smile | :)
The comment by Sico refers to an existing question on stack that answers this as not possible. How to change style of iframe content cross-domain?
If you are looking to do this in Javascript or JQuery that answer is correct, basically. You Cannot. It is not possible to alter the content of another domain.
A solution however, would be to use PHP to fetch the content of the target page and make it your own, there are several ways to do this such as curl http://php.net/manual/en/book.curl.php. You can then redisplay that content in any manner you like and apply any style you like. You can even ditch the iframe and inline it right into the rest of your content.
Be warned however, depending on the source domain, they may not approve of their content being re-used in this manner.

How to inform if Javascript is disabled in the browser [duplicate]

This question already has answers here:
How to detect if JavaScript is disabled?
(39 answers)
Closed 8 years ago.
I want to inform a user if javascript is disabled in the browser and tries to access my website. My information will be like: "Please enable javascript in your browser for better use of the website". So how to do this?
If informing your users to enable it is all you want to do, you don't need to depend on server-side code (in fact, I don't think you can). Just use a <noscript> element:
<noscript><p>Please enable JavaScript in your browser for better use of the website.</p></noscript>
Well there's the tag for displaying html only without javascript, but if you want to control the CSS depending on it the best thing to do is to then specify .no-js before any CSS that's only for if JS is disabled, then as your first meaningful line of javascript remove that class from the body (and possibly add a .with-js class to apply js-only styles).
You can also have no default class but add one only with JS, it comes down to personal preference though you can/do get a slight flash of content intended for no javascript with the former before the body class is removed.
<noscript>
<div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div>
very easy u can do it in this way this is how stack overflow use to alert user if java script is dsabled

Categories

Resources