chevys Posted December 2, 2009 Share Posted December 2, 2009 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"> Quote Link to comment https://forums.phpfreaks.com/topic/183750-javascript-help/ Share on other sites More sharing options...
KevinM1 Posted December 2, 2009 Share Posted December 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183750-javascript-help/#findComment-969911 Share on other sites More sharing options...
chevys Posted December 2, 2009 Author Share Posted December 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183750-javascript-help/#findComment-969934 Share on other sites More sharing options...
KevinM1 Posted December 2, 2009 Share Posted December 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183750-javascript-help/#findComment-969943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.