A
A
Alexander2015-11-10 15:33:51
JavaScript
Alexander, 2015-11-10 15:33:51

How to pass/get the data attribute in the following situation?

Friends, tell me how to pass the data-rat attribute in this case:

<div  class='dop' data-rat='8.50'></div>

$('div.dop').myRat({'tekr': $(this).data('rat') }); - не передается в функцию
$('div.dop').myRat({'tekr': 888 }); - передается

Thank you very much in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Gushchin, 2015-11-10
@iNikNik

Because this at the time of code execution is unlikely to point to div.pop.

var $pop = $('div.dop');
$pop.myRat({'tekr': $pop.data('rat') });

K
Konstantin Gromov, 2015-11-10
@Pathgk

Your this link is completely wrong, and $.fn.data has a different purpose than getting data attributes. Read the feature documentation before using it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question