Skip to content Skip to sidebar Skip to footer

Undefined Value Of $(this).data(value) With Jquery Click() Method

Im my Rails 5 app, I am building a dynamic menu to route users to a particular part of the site based on their location. When they click on a menu item from the home page a modal i

Solution 1:

ss_button element on itself doesn't have any data properties. So, this in that function which refers to <div class="ss_button">, points to an element that doesn't have any data properties. That's why $(this).data('id') returns undefined.

Solution 2:

var id = $(this).data('id');

Here $(this) refers to <div class="ss_button"> which have no data-id attribute.

So it will always comes(outputs) as undefined.

Post a Comment for "Undefined Value Of $(this).data(value) With Jquery Click() Method"