0

What is equivalent to

var input = document.getElementById("images"),
input.addEventListener("change", function (evt) {});

in jQuery?

1
  • All you're looking for, took me 10 seconds to Google both of them. get element by id in jQuery and change event with jquery.... Commented Jan 21, 2013 at 15:16

3 Answers 3

4
$('#images').on("change",function(evt){

});

.on() should be your first option, if your jquery is < v1.7 then you can use bind() instead.

For further references: Check the jQuery API Documentation.

Sign up to request clarification or add additional context in comments.

6 Comments

It says Uncaught TypeError: Object #images has no method 'on'
Then your jquery version is too old and you can use bind instead.
it definitely works: jsfiddle.net/pd7wv Do you have some other code occupying the $? try jQuery instead of $. Test this: $().jquery - it should give you the jquery version number.
Even without domready, it should not throw an error. The Set might be empty, but it's still a query object possessing the on method.
@Midhun apparently you fixed the problem - what exactly was it?
|
2
var input = $('#images')

input.bind("change",function(evt){

});

Comments

2

you can simply use

$('#images').change(function(evt) {

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.