I am new in Javascript and I am trying to test following code
<html>
<head>
<script src="jquery/jquery.min.js">
</head>
<body>
<input type="button" value="Click button">
<script type="text/javascript">
$(function(){
$('input')[0].on('click',function(){
alert('button clicked');
});
});
</script>
</body>
</html>
but when i open this html file in browser the button doesn't display
Script tags require a closing tag, which you've omitted:
<script src="jquery/jquery.min.js"></script>
^ close
By leaving it open, the browser is treating everything after the script tag as the script content.
Also your $('input')[0]
isn't right. That is getting the DOM element of the input, which has no jQuery wrapper and no .on()
function. If you are trying to match just the first input then:
$('input').first().on('click',function(){
Problems
$('input')
instead of $('input')[0]
, When you use $('input')[0]
you get DOM element which doesn't have click method.Use
<html>
<head>
<script src="jquery/jquery.min.js"></script>
</head>
<body>
<input type="button" value="Click button">
<script type="text/javascript">
$(function(){
$('input').on('click',function(){
alert('button clicked');
});
});
</script>
</body>
</html>
To avoid these kind of confusions, try to separate like below,
In HTML:
<html>
<head>
<script src="jquery/jquery.min.js"></script>
<script src="main.js"></script>
</head>
<body>
<input type="button" value="Click button">
</body>
</html>
In main.js
$(function(){
$('input').on('click',function(){
alert('button clicked');
});
});
For Demo
I have a string that I'd like to pull some content from using javascript. The string can have multiple forms as follows: [[(a*, b*) within 20]] or [[...(a*, b*) within 20]] where the "..." may or may ...
I have a string that I'd like to pull some content from using javascript. The string can have multiple forms as follows: [[(a*, b*) within 20]] or [[...(a*, b*) within 20]] where the "..." may or may ...
I'm making a chrome extension, and so far I'm just testing some things. The HTML for the extension is this: <!doctype html> <html> <head> <title>Title</title> &...
I'm making a chrome extension, and so far I'm just testing some things. The HTML for the extension is this: <!doctype html> <html> <head> <title>Title</title> &...
I have been having some trouble in creating a simple notification box. Basically the objective here when I click the submit button input type=button it will display a simple notification box like this....
I have been having some trouble in creating a simple notification box. Basically the objective here when I click the submit button input type=button it will display a simple notification box like this....
I was reading the javascipt code in some application and code was this getTotalFees:function(){ return this.grid &&this.grid.getStore().sum('fees'); } Now i am confused what ...
I was reading the javascipt code in some application and code was this getTotalFees:function(){ return this.grid &&this.grid.getStore().sum('fees'); } Now i am confused what ...