Jump to content

Combining 2 scripts


lbh2011

Recommended Posts

Hi,

 

Please could someone help me out - I'm sure the answer is very simple, but basically I have two scripts which I need to combine so that they work in parallel. Unfortunately I can't provide the rest of the code just yet, but each works on its own but not both together (when placed side by side in the head of the document).

 

The first:

 

<script type="text/javascript" src="js/jquery-1.7.1.min.js" ></script> 

<script type="text/javascript">

/* <![CDATA[ */
$(document).ready(function(){
	$("#Subject").change(function(){

		if ($(this).val() == "form1" ) {

			$("#div1").slideDown("fast"); //Slide Down Effect

		} else {

			$("#div1").slideUp("fast");	//Slide Up Effect

		}
	});

	$("#Subject").change(function(){

		if ($(this).val() == "form2" ) {

			$("#div2").slideDown("fast"); //Slide Down Effect

		} else {

			$("#div2").slideUp("fast");	//Slide Up Effect

		}
	});
});

/* ]]> */

</script>

 

The second:

 

<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript">
		/* <![CDATA[ */
window.addEvent('domready', function(){
                $('contact').addEvent('submit', function(e) {
                    new Event(e).stop();
                    var log = $('log_res').empty().addClass('ajax-loading');
                    this.send({
                        update: log,
                        onComplete: function() {
                            log.removeClass('ajax-loading');
                        }
                    });
                });
            });
			/* ]]> */
</script>

Link to comment
https://forums.phpfreaks.com/topic/255906-combining-2-scripts/
Share on other sites

jQuery and mootools do not natively get along with each other because by default they use the same $ namespace.  I don't have much experience with mootools but I know jQuery provides an easy solution for working with other libraries (and I suspect mootools probably has an equivalent). 

 

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

 

However, the *real* answer here is really that you should pick one library or the other instead of using both.  Which one is better depends on what you are ultimately trying to do, but based on the code you provided, both of them should be able to do those jobs. 

 

The benefits of using a single library are obvious:

 

- less bandwidth consumed

- faster load times, since you won't be loading 2 libraries

- not having to maintain multiple frameworks

- don't have to learn multiple frameworks

- don't have to deal with issues like this

 

 

Link to comment
https://forums.phpfreaks.com/topic/255906-combining-2-scripts/#findComment-1311842
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.