threepoint1416
threepoint1416

Reputation: 132

JS revision for jQuery 1.7+

So I have a code that looks something like this

$(".something").live({
   mouseover:function(e){
     //do stuff
   },
   mouseout:function(e){
     //do or undo other stuff
   }
});

But since this .live method is deprecated in jQuery1.7+, I have to do a bit of revising. To start with, it should look like:

$(document).on("mouseover",".something",function(e){
  //do stuff here
});

How about the mouseout thingy? Any quick way to merge the two or will I be forced to make separate coding for them? Thanks.

Upvotes: 2

Views: 100

Answers (2)

Naftali
Naftali

Reputation: 146350

$(document).on({
   mouseover:function(e){
     //do stuff
   },
   mouseout:function(e){
     //do or undo other stuff
   }
}, ".something");

Based on:

.on( events-map [, selector] [, data] )

From the doc

Upvotes: 2

user578895
user578895

Reputation:

You can leave the map:

$(document).on(
    {
         mouseover : function(){ ... }
        , mouseout : function(){ ... }
    }
    , '.something'
);

Upvotes: 4

Related Questions