简体   繁体   中英

How to fire Javascript code to be the last, when all the HTML/CSS and Javascript Codes are fired?

I have been updating a client website which only allows me to add script and style codes on limited areas. I've used FF "Inspect Elements" and can view the codes and can do tests using Edit CSS of the web dev add-on tool. However, I could not get to style the codes I see using a simple Javascript code. When I checked the code using "View Source", the code that i need to edit is not showing.

To get an idea of what I'm doing, here's a similar code. Objective is to style the DIV with green border when an img src contains the string "white":

HTML:

<div class="container">
    <img class="cropImg" src="http://placehold.it/150x150/f00&text=red" alt="red">
    <img class="cropImg" src="http://placehold.it/150x150/fff&text=white" alt="white">
    <img class="cropImg" src="http://placehold.it/150x150/00f&text=blue" alt="blue">
</div>

JavaScript:

$(document).ready(function(){
    var xColour = $("img[src*='white']");
    xColour.css('border','5px solid green');
});

I have also created a JSFiddle for quick viewing ==> http://jsfiddle.net/philcyb/q5cqomto/

QUESTION: Is there a way to fire my inserted Javascript as the last one to be fired?
Or if my question is not relevant, any thoughts shared is appreciated.

Thank you!

You can use following code to achieve what you want

$(window).bind("load", function() {

// code here });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM