# Javascript using jQuery.js and prototype.js doesnt work 2get

**URL:** <https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399>\
**Category:** Rails\
**Created:** [February 26, 2009, 7:20am UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399 "2009-02-26T07:20:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 26, 2009, 7:20am UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/1 "2009-02-26T07:20:40Z")

</div>

Hi…

M hving javascript “scripts.js” which uses jQuery.js in rails  
application. bt when it is used along with prototype.js, one of the  
javascripts which hs been included first in my application.rhtml  
fails…

Do some1 hv any solution how to make both the scripts work 2gether…

I tried using  
  
bt of no use. problem remains the same…

any suggestions are greatly appriciated…

thankx…

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 26, 2009, 7:23am UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/2 "2009-02-26T07:23:20Z")

</div>

include jquery and use jQuery.noConflict(); before you include  
prototypeand  
try again.

On Thu, Feb 26, 2009 at 2:20 PM, Radha L. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> I tried using
> 
> >

–  
TWRUG Blog:  
[http://blog.rubyonrails.org.tw](http://blog.rubyonrails.org.tw)

CFC on Rails:

> **[CFC on Rails](http://zusocfc.blogspot.com)**
>
> 火車請別撞我

Only two surfaces of a box:  
[http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 26, 2009, 8:48am UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/3 "2009-02-26T08:48:36Z")

</div>

Billy H. wrote:

> include jquery and use jQuery.noConflict(); before you include  
> prototypeand  
> try again.
> 
> On Thu, Feb 26, 2009 at 2:20 PM, Radha L. \<  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:
> 
> > I tried using
> > 
> > >

I did the same thing…  
first in included jQuery.js then

and at last prototype.js.. bt nt working..

below is my rhtml file…and i followed the sequence given below… My  
scripts.js is using jQuery.js.. Is it the proper sequence or do i need  
alteration… plz reply as early as u can…

 \<% if @artist %\>\<%= @artist.name %\> \<%= section\_title(params[:controller]) %\> : \<% end %\>DashGo

```
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<%= stylesheet_link_tag "style" %>
<%= stylesheet_link_tag "print", :media => "print" %>
<link rel="icon" type="image/png" href="/images/favicon.png">
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery.color.js" %>
<%= javascript_include_tag "scripts" %>
<script>
jQuery.noConflict();
</script>
<%= javascript_include_tag 'prototype' %>

```

```
<%= yield %>

<%= render :partial => 'layouts/footer' %>

<%= render :partial => 'layouts/google_analytics' %>

```

thanks

> –  
> TWRUG Blog:  
> [http://blog.rubyonrails.org.tw](http://blog.rubyonrails.org.tw)
> 
> CFC on Rails:  
> [http://zusocfc.blogspot.com](http://zusocfc.blogspot.com)
> 
> Only two surfaces of a box:  
> [http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 26, 2009, 8:58am UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/4 "2009-02-26T08:58:18Z")

</div>

I usually named $j for jQuery.

Then, you can use $j(…) to do something with jQuery and use $ to do  
something with Prototype.  
I think maybe you must modify some code in scripts.js or try include  
jquery.color.js and scripts.js after you define jQuery.noConflict();

\<%= javascript\_include\_tag “jquery” %\>

\<%= javascript\_include\_tag “jquery.color”, “scripts” %\>

On Thu, Feb 26, 2009 at 3:48 PM, Radha L. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> > >
> 
> below is my rhtml file…and i followed the sequence given below… My  
> section\_title(params[:controller]) %\> : \<% end %\>DashGo
> 
> \> CFC on Rails: \> http://zusocfc.blogspot.com \> \> Only two surfaces of a box: \> http://blog.pixnet.net/zusocfc
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
TWRUG Blog:  
[http://blog.rubyonrails.org.tw](http://blog.rubyonrails.org.tw)

CFC on Rails:

> **[CFC on Rails](http://zusocfc.blogspot.com)**
>
> 火車請別撞我

Only two surfaces of a box:  
[http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 26, 2009, 1:08pm UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/5 "2009-02-26T13:08:16Z")

</div>

Billy H. wrote:

> I usually named $j for jQuery.
> 
> Then, you can use $j(…) to do something with jQuery and use $ to do  
> something with Prototype.  
> I think maybe you must modify some code in scripts.js or try include  
> jquery.color.js and scripts.js after you define jQuery.noConflict();
> 
> \<%= javascript\_include\_tag “jquery” %\>
> 
> \<%= javascript\_include\_tag “jquery.color”, “scripts” %\>
> 
> On Thu, Feb 26, 2009 at 3:48 PM, Radha L. \<  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:
> 
> > > >
> > 
> > below is my rhtml file…and i followed the sequence given below… My  
> > section\_title(params[:controller]) %\> : \<% end %\>DashGo
> > 
> > \> CFC on Rails: \> http://zusocfc.blogspot.com \> \> Only two surfaces of a box: \> http://blog.pixnet.net/zusocfc
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> Hi..  
> Thanks for the suggestion.. bt it fails…  
> below is my scripts.js file… and it fails with the error

$(“table.data tr:nth-child(even)”) is null

i tried using jQuery in place of $ in scripts.js. it had been working  
properly. all the functionalities were working. but wen i implemented  
lightbox, lightbox was not working properly. bt wen i undo the changes  
in scripts.js lightbox works fine..

How to modify scripts.js.. below is the script.

/\*  
DashGo scripts (utilizing jQuery 1.2.3)  
Developed by Noah Lazar, Saforian  
\*/

/\* — Initialize page — \*/  
$(document).ready(function(){

// Stripe row colors  
$(“table.data  
tr:nth-child(even)”).not(“.even”).not(“.odd”).addClass(“even”);

// Insert document icons  
$(“a[href$=pdf]”).not(“:has(img)”).append(‘ ![(PDF)](https://www.ruby-forum.com/images/icon_pdf.gif)’);  
$(“a[href$=doc]”).not(“:has(img)”).append(‘ ![(Word Document)](https://www.ruby-forum.com/images/icon_word.gif)’);  
$(“a[href$=xls]”).not(“:has(img)”).append(‘ ![(Excel Spreadsheet)](https://www.ruby-forum.com/images/icon_excel.gif)’);  
$(“a[href$=ppt]”).not(“:has(img)”).append(‘ ![(Powerpoint Presentation)](https://www.ruby-forum.com/images/icon_powerpoint.gif)’);

// CSS3 first and last child replacement  
$(“.columns .col:last-child”).addClass(“last-child”);  
$(“.three .col:first-child”).addClass(“first-child”);

// Popup Help  
initPopupHelp();

// Hide/show boxes  
initToggleBoxes();

// Collapsable boxes  
initCollapsables();

// IE6 interface fixes  
if ($.browser.msie && $.browser.version \<= 6) {  
initIE6();  
}

// Selectable data tables  
initSelectables();

// Yellow fade messages (requires jquery.color.js plugin)  
$(“.notice, .warning”).animate({ backgroundColor:“#e7e7e7” }, 2200);

// Select box navigation  
(“select[rel=redirect]”).change(function(){  
location.href = $(this).val();  
});

});

// Toggle hide/show/edit for boxes  
function initToggleBoxes(){

// Hidden box initialization  
$(“#artistinfo”).hide();

// Show box  
$(“a[rel=show]”).click(function(){

```
// Show destination box
$(this.hash).slideToggle("fast");

// Hide this link (close link should be within box)
$(this).hide();

return false;

```

});

// Hide box  
$(“a[rel=hide]”).click(function(){  
var link = this;

```
// Hide box
$(this.hash).slideToggle("fast", function(){
  // Show original open link
  $("a[href=" + link.hash + "][rel=show]").show();

  // Cancel edit mode if possible
  $(link.hash).find("div.edit:visible a[rel=cancel]").click();

});

return false;

```

});

// Edit fields  
$(“a[rel=edit]”).click(function(){

```
// Hide the "view" box and show the "edit" box
$(this.hash)
  .find("div.view").hide()
  .siblings("div.edit").show();

return false;

```

});

// Cancel editing fields  
$(“a[rel=cancel]”).click(function(){

```
// Hide the "edit" box and show the "view" box
$(this.hash)
  .find("div.edit").hide()
  .siblings("div.view").show();

return false;

```

});

// Delete links  
$(“a[rel=delete]”).click(function(){  
return confirm(“Are you sure you want to delete this item?”);  
});

}

// Selectable data tables  
function initSelectables() {

$(“table.selectable tr:has(td)”).click(function(){

```
if ($(this).hasClass("active")) { return; }

// Go to destination based on row URL
var url = $(this).attr("rel");
if (url != "") { location.href = url; }

```

});

}

// Collapsable boxes  
function initCollapsables() {

// Collapse closed boxes  
$(“.collapsable.closed\>.wrapper”).hide();

// Add wrapper link for title text (to allow for keyboard navigation)  
$(“.collapsable .title\>h3”).not(“:has(a)”).wrapInner(“”);

// Process toggle  
$(“.collapsable .title\>h3\>a.toggle”).click(function(){

```
// Slide up and change arrow
$(this).parents(".collapsable").toggleClass("closed");

if ($.browser.msie && $.browser.version <= 6) {
  // Animation does not work in IE6
  $(this).parents(".title").siblings(".wrapper").toggle();
} else {
  $(this).parents(".title").siblings(".wrapper").slideToggle("fast");
}

return false;

```

});  
}

// Popup Help  
function initPopupHelp() {

// Since we’re fading, apply opacity fix to Firefox  
if ($.browser.mozilla && $(“.help”).size() \> 0) {  
$(“body”).css(“opacity”, “.99999”);  
}

// Add wrapper  
$(“.help”).wrapInner(‘’);

// Hide text  
$(“.help .text”).hide();

// Insert help icon  
$(“.help”).append(‘ ![Help](https://www.ruby-forum.com/images/icon_help.gif)’);

$(“.help”)  
// Hover action  
.hover(function(){  
// Fade in help text  
$(this).find(“span.text:hidden”).animate({ opacity:“show”,  
bottom:“-=20” }, “normal”);  
},function(){  
// Fade out help text  
$(this).find(“span.text:visible”).animate({ opacity:“hide”,  
bottom:“+=20” }, “fast”);  
})

```
// Keyboard tab access
.focus(function(){
  // Fade in help text
  $(this).find("span.text:hidden").animate({ opacity:"show", 

```

bottom:“-=20” }, “normal”);  
})  
.blur(function(){  
// Fade out help text  
$(this).find(“span.text:visible”).animate({ opacity:“hide”,  
bottom:“+=20” }, “fast”);  
});

}

// IE6 fixes for missing CSS features  
function initIE6(){

// Support :hover on selectable rows  
$(“table.selectable tr”).hover(function(){  
$(this).addClass(“hover”);  
}, function(){  
$(this).removeClass(“hover”);  
});

// Add [rel=delete] replacement class  
$(“a.button[rel=delete]”).addClass(“reldelete”);

// Add [type=text] replacement class  
$(“#artistinfo input[type=text]”).addClass(“typetext”);

// PNG support  
$(“img[src$=png]”).each(function(){  
var src = this.src;  
var div = document.createElement(“div”);

```
// Set replacement div properties
div.id = this.id;
div.className = this.className;
div.title = this.title || this.alt;
div.style.filter = 

```

“progid:DXImageTransform.Microsoft.AlphaImageLoader(src='” + this.src +  
“', sizing=‘scale’)”;  
div.style.width = this.width + “px”;  
div.style.height = this.height + “px”;

```
// Replace image with transparent div
this.replaceNode(div);

```

});

}

> –  
> TWRUG Blog:  
> [http://blog.rubyonrails.org.tw](http://blog.rubyonrails.org.tw)
> 
> CFC on Rails:  
> [http://zusocfc.blogspot.com](http://zusocfc.blogspot.com)
> 
> Only two surfaces of a box:  
> [http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 26, 2009, 3:34pm UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/6 "2009-02-26T15:34:52Z")

</div>

(function($){// Code  
$(document).ready(function(){});  
})(jQuery);

On Thu, Feb 26, 2009 at 8:08 PM, Radha L. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> > jquery.color.js and scripts.js after you define jQuery.noConflict();
> > 
> > > > >
> > > 
> > > –  
> > > i tried using jQuery in place of $ in scripts.js. it had been working  
> > > Developed by Noah Lazar, Saforian  
> > > $(“a[href$=pdf]”).not(“:has(img)”).append('\<img class=“icon”
> 
> // Collapsable boxes  
> // Yellow fade messages (requires jquery.color.js plugin)
> 
> // Show destination box  
> var link = this;
> 
> }  
> var url = $(this).attr(“rel”);  
> // Collapse closed boxes  
> $(this).parents(“.collapsable”).toggleClass(“closed”);  
> }
> 
> })  
> bottom:“+=20” }, “fast”);  
> $(“table.selectable tr”).hover(function(){  
> $(“#artistinfo input[type=text]”).addClass(“typetext”);  
> div.title = this.title || this.alt;
> 
> > Only two surfaces of a box:  
> > [http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
TWRUG Blog:  
[http://blog.rubyonrails.org.tw](http://blog.rubyonrails.org.tw)

CFC on Rails:

> **[CFC on Rails](http://zusocfc.blogspot.com)**
>
> 火車請別撞我

Only two surfaces of a box:  
[http://blog.pixnet.net/zusocfc](http://blog.pixnet.net/zusocfc)

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [September 23, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/7 "2009-09-23T14:15:44Z")

</div>

Billy H. wrote:

> include jquery and use jQuery.noConflict(); before you include  
> prototypeand  
> try again.

Thanks. Simply moving the JS include of prototype.js after all of my  
other JS includes did the trick for me. AJAX now works for my rails  
app.  
Andy

---

<div class="post-metadata">

**Author:** ![radha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecb155/32.png) [@radha](https://www.ruby-forum.com/u/radha)\
**Post date:** [February 27, 2009, 4:07am UTC](https://www.ruby-forum.com/t/javascript-using-jquery-js-and-prototype-js-doesnt-work-2get/161399/8 "2009-02-27T04:07:28Z")

</div>

On Wed, Feb 25, 2009 at 10:20 PM, Radha L. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> I tried using
> 
> bt of no use. problem remains the same…
> 
> any suggestions are greatly appriciated…
> 
> thankx..

Hi, please read the following:

> **[Avoiding Conflicts with Other Libraries | jQuery Learning Center](https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/)**

Good luck,

-Conrad
