1

I have two script in javascript/jquery. How i will combine in one. On body load this function run

<script type="text/javascript">
    window.onload=function() {
       var tId = setInterval(function() {
         document.getElementById("link1").disabled=!navigator.onLine;
       },250);
                  </script>

    <script>   
       var status = navigator.onLine;
    if (status) {
    $("#link1").removeClass('diconnected').addClass('connected');
    $("#link1").data('disabled',true);
    } else {
    $("#link1").removeClass('connected').addClass('diconnected');
    }
    }
    </script>
4
  • 1
    Have you tried anything? Stackoverflow is not an automatic-free-online-weird-code-merging tool Commented Mar 13, 2014 at 22:18
  • 1
    Have you started with the obvious and just removed the </script> <script> from between them? Commented Mar 13, 2014 at 22:20
  • @Pointy: yes i did that, but not confirm it will behave proper or not Commented Mar 13, 2014 at 22:22
  • 1
    It will; so long as the code isn't throwing an error, the semantics of two script blocks right next to each other is the same as one big block. In your first script, you're missing a }. Commented Mar 13, 2014 at 22:26

2 Answers 2

1
$(document).ready(function(){  
    var status = navigator.onLine;
if (status) {
$("#link1").removeClass('diconnected').addClass('connected');
$("#link1").data('disabled',true);
} else {
$("#link1").removeClass('connected').addClass('diconnected');
}window.onload=function() {
           var tId = setInterval(function() {
             document.getElementById("link1").disabled=!navigator.onLine;
           },250);
       }});

try this

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

Comments

0

Your first script is missing a closing bracket }

If you add in a } you can remove the closing and opening script tags.

Additionally, you may want the second bit of code within the window.onload function, which would mean you could put the closing bracket } after the 2nd scripts code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.