Reputation: 1
i want to add javascript in my html form modal. but i got error "uncaught referenceError: $ is not defined" when i define count variable.
So ,how can i resolve this question.
<div class="modal">
<form id="multiform">
<script rel="javascript" type="text/javascript" href="/static/js/jquery.min.js">
var count=$('select#ip option:selected').length;
alert(count);
/*code more*/
</script>
</form>
</div>
Upvotes: 0
Views: 38
Reputation: 68433
There are 3 mistakes
src
instead of href
.src
to a script
tag, then script inside that tag will be ignored.body
tag or in head
tag.Demo
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal">
<form id="multiform">
</form>
</div>
<script>
var count = $('select#ip option:selected').length;
alert(count);
</script>
Upvotes: 3
Reputation: 235
Try this. you are using href insted of src
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal">
<form id="multiform">
<script type="text/javascript">
var count=$('select#ip option:selected').length;
alert(count);
/*code more*/
</script>
</form>
</div>
Upvotes: 0