Reputation: 17268
I just started my very first JavaScript tutorial couple of days ago. I've come to the point where they explain the use of libraries. Two questions in mind thus far:
getElementById
is implemented as $("#id")
in jQuery and as $("id")
in Prototype. Why the inconsistency?
If both libraries are included, how can the browser decide which object should be returned for $("")
?
Upvotes: 0
Views: 381
Reputation: 149020
1. Why the inconsistency?
The two libraries were implemented at different times, by different teams, and do very different things. Why would you expect consistency?
2. If both libraries are included, how can the browser decide which object should be returned for
$("")
?
That depends on exactly how you include them. However, jQuery has facilities to avoid conflicts like this, see jQuery.noConflict
. It's been some time since I've used prototype, but it may have similar functionality, as well.
Upvotes: 1
Reputation: 981
This link will help you to understand handling conflicts while using jquery with other library like prototype http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/
Upvotes: 0
Reputation: 239301
The browser doesn't "decide", whichever one you include second overwrites the first.
In situations where two libraries are fighting over $
, use jQuery
instead:
jQuery('#id') // same as $('#id') when $ == jQuery
You can then return control over $
to Prototype with jQuery.noConflict
.
As for the inconsistency, they're different libraries written at different times by different people, with no intention of making them compatible. Consistency was never a consideration.
Upvotes: 1