Reputation: 1164
I was wondering how to use javascript when jquery has already been declared in the head. Javascript, in my opinion, is better to use for specific tasks, and jQuery is also better to use for some tasks. I am using jQuery, and jQuery UI, but it doesn't really matter what version I am using.
I have some simple jQuery here:
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left: '250px'});
});
});
and I have some javascript right here:
document.getElementById('div2').appendChild(
document.getElementById('C')
);
I don't want to have the jQuery translated to js, or visa versa.
Upvotes: 0
Views: 255
Reputation: 1164
You can declare the jQuery after all the javascript, like this:
<script>
document.getElementById('div2').appendChild(
document.getElementById('C')
);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left: '250px'});
});
});
</script>
I know this should work.
Upvotes: 1
Reputation: 4539
Well, you can combine both jquery and javascript in the same script tag.
$(document).ready(function(){
var something = document.getElementById('productId');//javascript
$("button").click(function(){
$("div").animate({left: '250px'});//jquery.
});
});
Javascript vs Jquery
JavaScript is a language. jQuery is a library built with JavaScript to help JavaScript programmers who are doing common web tasks. Which is the best between JavaScript or JQuery is a contentious discussion, really the answer is neither is best. They both have their roles.For some application what is needed is straight JavaScript development. But for most websites JQuery is all that is needed. What a web developer needs to do is make an informed decision on what tools are best for their client. Someone first coming into web development does need some exposure to both technologies just using JQuery all the time does not teach the nuances of JavaScript and how it affects the DOM. Using JavaScript all the time slows projects down and because the JQuery framework has ironed most of the issues that JavaScript will have between each web browser it makes the deployment safe as it is sure to work across all platforms. Author: Tusar Gupta
Upvotes: 5
Reputation: 5632
jQuery is a library, Javascript is a language. jQuery is built using javascript, your language will not be changed by including jQuery. It just exposes pre-built functions for you to use.
Upvotes: 1