Skip to content Skip to sidebar Skip to footer

My Script Only Working From Console

I have a script that I put inside my html doc. when I load the html page the script is not working,but when I put the script inside the console then the script is working an making

Solution 1:

You're most likely running that script before the elements that it references exist.

Make sure that the <script> tag comes later in the page than the element with the class table or wrap your entire script in:

$(function(){

 ... Your entire script

});

in order to ensure that it does not execute until the DOM is ready.

Solution 2:

Try wrapping the whole thing with this:

$(document).ready(function () { /* existing code */ });

The browser may be executing your code before the page has loaded and therefore before the elements exist.

Solution 3:

A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside $( window ).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.

Try wrapping your code in this

$(document).ready(function() {
    // Your code here
});

The Source

Post a Comment for "My Script Only Working From Console"