Using jQuery.prop Method to Set Function Properties

I am trying to assign a function to a property to group items using .prop()

 $('.whatever').prop({MyProp:MyFunc}); 

By carefully studying the documentation for this function, it seems that there is a special behavior when the value is a function, and a function is NOT assigned to the property, and the function returns a value.

Is there an easy way for this or should I just use

 $('.whatever').each(function(id, item){item.MyProp=MyFunc;}); 
+4
source share
1 answer

.prop() not suitable for this purpose. This is why you have a .data() method.

 $('.whatever').data('MyFunc', MyFunc); // somewhere else: var MyFunc = $('.whatever').data('MyFunc'); MyFunc(args); 
0
source

Source: https://habr.com/ru/post/1491628/


All Articles