Home | Looking for something? Sign In | New here? Sign Up | Log out

Selasa, 08 Januari 2013

Cara Mengatasi Konflik Antara jQuery Dan MooTools

Selasa, 08 Januari 2013

jQuery dan MooTools adalah salah dua Framework JavaScript yang banyak digunakan. Masing-masing memiliki kelebihannya sendiri-sendiri (Untuk detail feature masing-masing framework silakan cek sendiri di website mereka). Lalu bisakah kita menggunakan keduanya secara bersamaan? Tentu saja bisa.
Yang harus diperhatikan adalah bahwa jQuery menggunakan tanda $ sebagai shortcut untuk pemanggilan jQuery, sedangkan MooTools pun menggunakan $() sebagai shortcut untuk mempersingkat document.getElementById().
Jika kita meload jQuery dan MooTools secara bersamaan di satu halaman, maka bisa dipastikan bakalan terjadi konflik di antara keduanya.
Namun untungnya, kunci untuk mengatasi masalah tersebut sudah disediakan oleh jQuery, yaitu dengan menjalankan script jQuery.noConflict() setelah jQuery diload.
  1. <script type=text/javascript src=mootools.js></script>
  2. <script type=text/javascript src=jquery.js></script>
  3. <script type=text/javascript>
  4. jQuery.noConflict();
  5. </script>
Kemudian di dalam script jQuery yang kita buat juga harus menggunakan jQuery sebagai pengganti $
  1. jQuery(document).ready(function() {
  2. jQuery('#content').html('Hello');
  3. });
Jika pemanggilan menggunakan jQuery terasa terlalu panjang atau kurang keren, kita juga bisa membuat variabel sendiri sebagai penggantinya, misalnya sebagai berikut :
  1. var test= jQuery.noConflict();
  2. //lalu gunakan nama variabel tersebut sebagai pengganti jQuery
  3. test(document).ready(function() {
  4. test('#content').html('Hello');
  5. });

6 :

byodbuzz04 mengatakan...

David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools
Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton
of engaging advice and insight into front-end technologies. Even more obvious is his passion
for open source contribution and trial-and-error development, making his blog one of the
most honest and engaging around.
Website: davidwalsh.name

byodbuzz08 mengatakan...

David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
Website: davidwalsh.name

byodbuzz05 mengatakan...

David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
Website: davidwalsh.name

byodbuzz05 mengatakan...

David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
Website: davidwalsh.name

byodbuzz03 mengatakan...

David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
Website: davidwalsh.name

byodbuzz03 mengatakan...

David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
Website: davidwalsh.name

Posting Komentar

Related Posts Plugin for WordPress, Blogger...
 

Contoh Pilihan

SMS GRATIS

Like Box