Problem 1
A script element loads a single script.
This can be from code between the start tag and the end tag or a URL specified by the src
attribute.
It cannot load both.
If you provide both (as you are doing) the src
attribute will be used and the inline script will be ignored.
You need two script elements. One to load the jQuery library and one to load your script which uses that library.
Problem 2
There are no input
elements in your document at the time the script runs. See Why does jQuery or a DOM method such as getElementById not find the element?
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
$('input').toggle(
function() {
$('img').attr('src', 'https://placeimg.com/150/150/animals');
},
function() {
$('img').attr('src', 'https://placeimg.com/150/150/people');
}
);
});
</script>
<input value="change image" type="button" />
<img src="https://placeimg.com/150/150/animals" />
Problem 3
This doesn't look like the behaviour you want (toggle doesn't toggle between two functions each time something is clicked), and you probably want to be using a click event handler instead.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
const one = 'https://placeimg.com/150/150/animals';
const two = 'https://placeimg.com/150/150/people';
$('input').on('click', toggle);
function toggle() {
const current = $('img').attr('src');
$('img').attr('src', current === one ? two : one);
}
});
</script>
<input value="change image" type="button" />
<img src="https://placeimg.com/150/150/animals" />