0

I want to apply/bind event only on specific DIV ID and Textarea. Then How can I achieve this?

I have below code

jQuery("#dataContent").bind("click change keypress"....){
    .....
}

I want to apply above three events only on Textarea and not on other HTML elements. Then How can I achieve this?

Can I do like below?

jQuery("#dataContent textarea")

Because currently above three events creating issue with file input and checkbox.

Any help would be heartily appreciated :)

Note: I'm facing this issue since long and not able to resolve it till today :(

3 Answers 3

1

Yes you can like,

$("#dataContent textarea").on("click, change, keypress", function() {

});

OR

$("#dataContent").on("click, change, keypress","textarea", function() {

});

You can use it like

$( "#dataContent textarea" ).on({
   click: function() {
       alert("click");
   }, change: function() {
       alert("change");
   }, keypress: function() {
       alert("keypress");
   }
});

Read on()

Demo

0
0

Just try like this.

$("#dataContent").on("click, change, keypress", function() {

});

reference

0
$("#dataContent ")
.on("click, change, keypress","textarea", function() {

});

reference .on

3
  • How can I exclude checkbox and fileinput or any other HTML tags other than Textarea? And will work comma (,) as event separator?
    – Smile
    Oct 23, 2013 at 4:56
  • @Rituraj if you are using textarea as second parameter in on() then why you are using not() to exclude input elements ,and if I want to exclude type="email", type="date" then you will append the list of input elements in not()? You can not use $("#dataContent ").not("input"). for all input elements? Oct 23, 2013 at 5:05
  • thanks for focus @RohanKumar some times it happen :) Oct 23, 2013 at 5:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.