Jump to content

Javascript help?


chevys

Recommended Posts

I am trying to insert more than one javascript in a .php file is there a proper way to do this?

 

They seem to cancel each other out??

 

<link rel="SHORTCUT ICON" href="favicon.ico" />

<link href="/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/>

<script src="scripts/jquery-1.2.3.min.js">

<script src="facebox/facebox.js">

</script>

<script>

  // When the document loads do everything inside here ...

  $(document).ready(function(){

 

// When a link is clicked

$("a.tab").click(function () {

 

 

// switch all tabs off

$(".active").removeClass("active");

 

// switch this tab on

$(this).addClass("active");

 

// slide all content up

$(".content").slideUp();

 

// slide this content up

var content_show = $(this).attr("title");

$("#"+content_show).slideDown();

 

});

 

  });

 

</script>

<script>

jQuery(document).ready(function($) {

      $('a[rel*=facebox]').facebox({

        loading_image : 'loading.gif',

        close_image  : 'closelabel.gif'

      })

    })

</script>

 

<style type="text/css">

Link to comment
Share on other sites

Think about what you're writing:

 

When the document is ready, the code in the first script tag is what I want to be run.

 

When the document is ready, the code in the second script tag is what I want to be run.

 

Notice there's no 'and' or 'or' between those two statements.  You're overwriting what you want to be done with the second bit of script instead of combining the two.

 

There's only one document in play here - your site.  Thus, it can only be readied once.  Combine your code.

Link to comment
Share on other sites

I am new to all of this and I am not sure how to add the AND statement to seperate the 2.

 

Your advice makes complete since, I just dont know what to do with it. :(

 

Instead of two scripts, combine them. 

 

<script type="text/javascript">
   // When the document loads do everything inside here ...
   $(document).ready(function(){
      // When a link is clicked
      $("a.tab").click(function () {
         // switch all tabs off
         $(".active").removeClass("active");
         
         // switch this tab on
         $(this).addClass("active");
         
         // slide all content up
         $(".content").slideUp();
         
         // slide this content up
         var content_show = $(this).attr("title");
         $("#"+content_show).slideDown();
      });

      $('a[rel*=facebox]').facebox({
         loading_image : 'loading.gif',
         close_image   : 'closelabel.gif'
      }) 
   });
</script>

 

You have two things going on here:

 

1. You tie some actions to the click event of an element

2. You tie some actions to the facebox

 

As you can see, both of these can be done in the same script.  And, again, since there's only one document - the web page itself - you can only have one $(document).ready() function anyway.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.